انتقل إلى المحتوى الرئيسي

كيفية مسح محتويات الخلية المحددة إذا تغيرت قيمة خلية أخرى في إكسيل؟

لنفترض أنك تريد مسح نطاق من محتويات الخلية المحددة إذا تم تغيير قيمة خلية أخرى ، كيف يمكنك القيام بذلك؟ سيوضح لك هذا المنشور طريقة لحل هذه المشكلة.

امسح محتويات الخلية المحددة إذا تغيرت قيمة خلية أخرى برمز VBA


امسح محتويات الخلية المحددة إذا تغيرت قيمة خلية أخرى برمز VBA

كما هو موضح أدناه ، عند تغيير القيمة في الخلية A2 ، سيتم مسح المحتويات الموجودة في الخلية C1: C3 تلقائيًا. الرجاء القيام بما يلي.

1. في ورقة العمل ، ستقوم بمسح محتويات الخلية بناءً على تغييرات خلية أخرى ، انقر بزر الماوس الأيمن فوق علامة تبويب الورقة وحدد عرض الرمز من قائمة السياق. انظر لقطة الشاشة:

2. في الافتتاح ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، انسخ والصق رمز VBA أدناه في نافذة التعليمات البرمجية.

كود فبا: امسح محتويات الخلية المحددة إذا تغيرت قيمة خلية أخرى

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A2")) Is Nothing Then
        Range("C1:C3").ClearContents
    End If
End Sub

ملاحظات: في الكود ، B2 هي الخلية التي ستقوم بمسح محتويات الخلية بناءً عليها ، و C1: C3 هو النطاق الذي ستقوم بمسح المحتويات منه. الرجاء تغييرها كما تريد.

3. اضغط على قديم + Q مفاتيح لإغلاق ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

ثم يمكنك رؤية المحتويات في النطاق C1: C3 يتم مسحها تلقائيًا عندما تتغير القيمة في الخلية A2 كما هو موضح أدناه لقطة الشاشة.


مقالات ذات صلة:

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 50٪ ، ويقلل مئات النقرات بالماوس كل يوم!
Comments (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hallo,

Dankeschön für die Hilfe.


LG Stefan
This comment was minimized by the moderator on the site
Hallo,
ich möchte das Makro bitte so erweitern, wenn ich in B2 klicke, das nur C2 gelöscht wird, wenn ich in B3 klicke dann soll nur C3 gelöscht werden usw. bis B100 dann soll nur C100 gelöscht werden.
Und das soll auch wechelseitig funktionieren.
Wenn ich in C2 klicke dann soll nur B2 gelöscht werden usw.

Vielen Dank im Vorraus

LG Stefan




Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20220721
If Target.Cells.Count > 1 Then Exit Sub
If (Not Intersect(Target, Range("B2")) Is Nothing) And (Target.Value = "Yes") Then
Range("B3").ClearContents
Else
If (Not Intersect(Target, Range("B3")) Is Nothing) And (Target.Value = "Yes") Then
Range("B2").ClearContents
End If
End If
End Sub
This comment was minimized by the moderator on the site
Hi Stefan,

The following VBA can acheive: when the value of column A is changed, the corresponding cell in column C of the same row will be cleared.
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20221013
    Dim xRight As Range
    Dim KeyCells As Range
    Set KeyCells = Range("A:A")
    Set xRight = Target.Offset(0, 3)
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        xRight.ClearContents
    End If
End Sub
This comment was minimized by the moderator on the site
Hola, estoy trabajando una base de datos en OFFICE ONLINE a traves de ONEDRIVE, quiero que al PONER "CANCELADO" o "NOSHOW" elimine el contenido de la fila seleccionada.
This comment was minimized by the moderator on the site
Hi Angel,
The VBA code does not work in Office Online. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hello,
The code below works as advertised but, the following problems occurs:

Firstly, when resizing the targeted table, all the table data is cleared AND, all but column 1 headers are re-labelled to "Column1, Column2, etc. AND the workbook autosave itslef and kills the undo.

Secondly, when deleting any table row, I get a "Run-time error 1004 (Method Offset of object Range failed.


Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("F3:F500")) Is Nothing Then
     Target.Offset(0, 1).ClearContents
    ElseIf Not Intersect(Target, Range("G3:G500")) Is Nothing Then
        Target.Offset(0, 1).ClearContents
        Target.Offset(0, 2).ClearContents
    ElseIf Not Intersect(Target, Range("H3:H500")) Is Nothing Then
        Target.Offset(0, 1).ClearContents
    End If
End Sub


Any idea of what could be wrong?

Thanks in advance!
This comment was minimized by the moderator on the site
Hallo,

Zu Punkt 3.
Die Taste "Andere" Finde ich nicht auf meiner Windows Tastatur. Ich Habe Strg, Alt, Tab... allerdings die Taste Andere gibt es auf meiner Tastatur leider nicht.

Lieben Gruß Mathias
This comment was minimized by the moderator on the site
Hi Mathias,
If you can't find the corresponding key on the keyboard. You can just click the Save button in the Microsoft Visual Basic Applications window to save the code and then manually close this window.
This comment was minimized by the moderator on the site
Помогите с решением, VBA не знаю. Мне нужно при изменении ячейки удалить данные из другой и чтобы это дейстовало на весь столбец.
Меняю А2 удаляется из G2, меняю А3 удаляется из G3, меняю A6 удаляется из G6 и т.д.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2")) Is Nothing Then
Range("G2").ClearContents
End If
End Sub


Данный код хорош для одной ячейки, а как его размножить на все ячейки столбца?
This comment was minimized by the moderator on the site
Hi Наталья,
The following VBA code can help you solve the problem. Please give it a try.

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20221013
    Dim xRight As Range
    Dim KeyCells As Range
    Set KeyCells = Range("A:A")
    Set xRight = Target.Offset(0, 6)
    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        xRight.ClearContents
    End If
End Sub
This comment was minimized by the moderator on the site
Buongiorno, avrei bisogno di cancellare una serie di caselle (un rettangolo, quindi su più righe e colonne) in base al valore di un'altra cella. es: se la cella A2 è inferiore di 12, il quadrato con vertici opposto C2 : F4 venga cancellato.
Grazie mille
This comment was minimized by the moderator on the site
Hi Pietro,
Sorry I don't quite understand your question. Do you mind uploading a screenshot of your data?
This comment was minimized by the moderator on the site
Hello,

Just looking for an easy way to make it so if "B2" has selected "Yes" from the data validation list, cell B3 would clear it's data... and vice-versa: If "B3" has selected "Yes" from the data validation list, cell "B2" would clear it's data.

Basically B2 or B3 can say "Yes" (from the data validation list) but never at the same time, one should clear the other.
This comment was minimized by the moderator on the site
Hi Jeff,
The following VBA code can do you a favor. Please give it a try.
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20220721
If Target.Cells.Count > 1 Then Exit Sub
    If (Not Intersect(Target, Range("B2")) Is Nothing) And (Target.Value = "Yes") Then
        Range("B3").ClearContents
        Else
        If (Not Intersect(Target, Range("B3")) Is Nothing) And (Target.Value = "Yes") Then
        Range("B2").ClearContents
    End If
    End If
End Sub
This comment was minimized by the moderator on the site
Bonjour tout le monde,

Besoin d'aide, j'ai besoin d'effacer le contenu d'une cellule de la colonne "I" si la cellule (de la même ligne) de la colonne "O" =0, sur environ 2000 lignes avec des titres tout le 10 lignes environ.
This comment was minimized by the moderator on the site
Is it possible to clear specified cell contents if the trigger cell contains a specific number? Say, IF cell A1 = 1, then clear Cells A2:A4?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations