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

كيفية إخفاء أو إظهار زر الأمر بناءً على قيمة الخلية المحددة في إكسيل؟

لنفترض أنك تستخدم زر الأمر لتشغيل برنامج نصي لـ VBA في ورقة العمل الخاصة بك. عندما يكون برنامج VBA النصي غير مستخدم في بعض الحالات ، فإنك تحتاج إلى جعل زر الأمر مخفيًا بدلاً من عرضه في ورقة العمل. وقم بعرضه مرة أخرى عند الحاجة إلى برنامج VBA النصي. تتحدث هذه المقالة عن إخفاء أو إظهار زر الأمر بناءً على قيمة خلية محددة في Excel. الرجاء القيام بما يلي.

إخفاء أو إظهار زر الأمر بناءً على قيمة الخلية المحددة برمز VBA


إخفاء أو إظهار زر الأمر بناءً على قيمة الخلية المحددة برمز VBA

يمكنك تشغيل رمز VBA أدناه لإخفاء أو إظهار زر الأمر بناءً على قيمة الخلية المحددة في Excel.

1. انقر بزر الماوس الأيمن فوق علامة تبويب الورقة التي تحتوي على زر الأمر الذي تريد إظهار إخفاءه ، ثم انقر فوق عرض الرمز من قائمة النقر بزر الماوس الأيمن.

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

كود فبا: إخفاء أو إظهار زر الأمر بناءً على قيمة الخلية المحددة

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    If Cells(1, 1).Value <> "1" Then
        Me.CommandButton1.Visible = True
    Else
        Me.CommandButton1.Visible = False
    End If
    Application.ScreenUpdating = True
End Sub

ملاحظات: في الكود ، الخلايا (1 ، 1), 1 و زر الأوامر1 أشر إلى أنه سيتم إخفاء CommandButton1 عندما تحتوي الخلية A1 على الرقم 1 ، وعرضه إذا كانت الخلية A1 تحتوي على أي قيم أخرى باستثناء الرقم 1. انظر أدناه لقطة الشاشة. ويمكنك تغييرها بناءً على حاجتك.


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

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

🤖 مساعد 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 (14)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Cool idea. Pity it doesn't work :(
This comment was minimized by the moderator on the site
Der Code funktioniert wie er ist prima.
Ich würde nur gerne den Button bei jeder 0 und leeren Zelle ausblenden lassen. Irgendwie bekomme ich es nicht hin. Es funktioniert immer nur entweder oder. Könnten Sie mir bitte weiter helfen danke
This comment was minimized by the moderator on the site
Hi Christoph,

Sorry I don't understand what you mean. For clarity, please attach a sample file or a screenshot with your data and desired results.
This comment was minimized by the moderator on the site
Hola!
Alguien sabe como puedo hacer para que el boton comando aparezca o desaparezca segun información de otra hoja?
El ejemplo está muy bueno, pero las celdas son de la misma hoja donde esta el boton. Yo necesito ocultar un boton segun info de otra hoja.

Gracias!
This comment was minimized by the moderator on the site
Hi,
Suppose, the value used to display or hide the command button locates in A1 of Sheet1, and the comman button locates in Sheet2. Please open the Sheet1, right click the sheet tab and click View Code. In the opening Microsoft Visual Basic for Applications window, copy the following VBA code into the Sheet1 (Code) window, and then press the Alt + F11 keys to close it.
Note: Please change Cells(1, 1), "1" and "Sheet2" as you need.
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    If Cells(1, 1).Value <> "1" Then
        Sheets("Sheet2").CommandButton1.Visible = True
    Else
        Sheets("Sheet2").CommandButton1.Visible = False
    End If
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
hola, el codigo esta bien? es que no me funciona y ya intente varias cosas para que funcione y nana, ayuda por favor es que lo necesito para algo importante :c
This comment was minimized by the moderator on the site
For some reason after the button go from invisible back to visible, the button no longer works. If I alt + F11 into the code select the XXX() sub and run with F5 the code works for my macro. Why doesn't it work when i click the button anymore? in properties 'Enabled' is set to true
This comment was minimized by the moderator on the site
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Cells(1, 1).Value <> "1" Then
Me.Shapes("Button 1").Visible = True
Else
Me.Shapes("Button 1") End If
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hello

I am new to VBA, I have put this code into a new Excel. One CommnadButton, on Sheet1 but the code doesnt work.

Do I have to do anything before this?


Thanks in Advance
This comment was minimized by the moderator on the site
Use the ActiveX Control Button.
This comment was minimized by the moderator on the site
I've put this code in and entered my button name (Finish), referenced the reference cell (P11 - 16, 11) but every time I make a change to the reference cell (P11) I get a compile error and it highlights the ".Finish" section of the code, seemingly meaning the button name I entered "Finish" is not found on the worksheet. I've confirmed, both in the drop down area to the left of the formula bar and in the "define name" area on the Formula tab that my button name is, in fact, "Finish", but it still does not work.


Any help?
This comment was minimized by the moderator on the site
Hi Bryce,
I changed the button name to "Finish" in my worksheet, and it works well without any error displaying.
Do you mind testing the code in a new blank workbook?
Thank you for your comment.
This comment was minimized by the moderator on the site
hola que tal, tengo un boton con macro, que me devuelve a una hoja 'menu', pero no quiero que ese boton aparezca en la hoja menu como le puedo hacer?'


saludos.-
This comment was minimized by the moderator on the site
Hola Sebastia,

Dónde debería mostrarse?
- Uno es la hoja de menú
- El botón está integrado en una hoja diferente, no?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations