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

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

في الواقع ، يمكن إخفاء شكل معين أو إظهاره بناءً على قيمة خلية محددة. يمكن أن تساعدك الطريقة التالية.

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


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

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

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

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

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

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = 1 And Target.Column = 1 Then _
        Me.Shapes("Oval 6").Visible = (Cells(1, 1).Value = 1)
End Sub

ملاحظة: في الكود:

1) الصف = 1 و العمود = 1 تشير إلى الخلية المحددة الموجودة في الصف الأول والعمود الأول ، والخلايا (1 ، 1) هي الخلية المقابلة A1.
2) القيمة = 1، الرقم 1 هو القيمة المحددة التي تريد إظهار الشكل بناءً عليها.
شنومكس) "البيضاوي شنومكس"هو اسم شكل معين.

يمكنك تغييرها بناءً على حاجتك.

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

من الآن فصاعدًا ، عند إدخال الرقم 1 في الخلية A1 ، يكون الشكل "البيضاوي 6" غير مخفي. ولكن إذا أدخلت قيمة أخرى مثل الرقم 2 في الخلية A1 ، فسيتم إخفاء الشكل "البيضاوي 6" على الفور.


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

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

🤖 مساعد 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
Hello,

thank you for making this guide!

I have one question:
If i need a shape to show up based on two or more values, how is this done?
This comment was minimized by the moderator on the site
Hi Kasper Pedersen,

Suppose you want to show up a shape named "Oval 4" when both cells A1 and C8 contain the specified values (1 and 2 respectively), and if either of the cells is cleared (i.e., its value becomes empty), the shape will set to invisible. You can try the following VBA code to get it done.

Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("A1").Value = 1 And Range("C8").Value = 2 Then
        Me.Shapes("Oval 4").Visible = True
    ElseIf Range("A1").Value = "" Or Range("C8").Value = "" Then
        Me.Shapes("Oval 4").Visible = False
    End If
End Sub
This comment was minimized by the moderator on the site
Thanks, but i want the shape not to be visible if the value is diffrent than "1" and "2" as shown in your example. eg. if the value is diffrent from 1 in cell A1 the shape becomes invisible. Is it possible?
This comment was minimized by the moderator on the site
This article doesn't give any hint as to how one gets the name of a shape.

I have checked the name manager and the object manager in VBA as well as the context menu - there is no "Properties" menu for shapes.

So, where is the shape name?
This comment was minimized by the moderator on the site
Hi Cornan,
The shape name will be displayed on the Name box of worksheet when selecting the shape. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
2 questions:

1. I cant seem to get this code to run and i dont understand why... copied and pasted it exactly as it is there...help!!!


2. how do i change it for shapes like Shapes.Range(Array("Rounded Rectangle 1"))
This comment was minimized by the moderator on the site
Hi Gus,
You must miss something in the operation.
Supposing your shape name is "Rounded Rectangle 1", please copy the below code into the worksheet code window (this worksheet should contain the specified shape "Rounded Rectangle 1").
From now on, only typing number 1 into A1 cell can display the shape "Rounded Rectangle 1". If you type in other content, the shape will be hidden.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 And Target.Column = 1 Then _
Me.Shapes("Rounded Rectangle 1").Visible = (Cells(1, 1).Value = 1)
End Sub
This comment was minimized by the moderator on the site
You left out the ":"
This comment was minimized by the moderator on the site
I am a newbie in VBA Excel. I am working with this code and I would like to optimize it. This code makes a shape visible on an active cell if value is 1 other values hide it. Range includes J13:AC161. If I will use the code below, it will take me more lines of code. Any help will be much appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("E13").Value = 1 Then
ActiveSheet.Shapes("rt1").Visible = True
Else
ActiveSheet.Shapes("rt1").Visible = False
End If

If ActiveSheet.Range("F13").Value = 1 Then
ActiveSheet.Shapes("rt2").Visible = True
Else
ActiveSheet.Shapes("rt2").Visible = False
End If

If ActiveSheet.Range("G13").Value = 1 Then
ActiveSheet.Shapes("rt3").Visible = True
Else
ActiveSheet.Shapes("rt3").Visible = False
End If

If ActiveSheet.Range("H13").Value = 1 Then
ActiveSheet.Shapes("rt4").Visible = True
Else
ActiveSheet.Shapes("rt4").Visible = False
End If

If ActiveSheet.Range("I13").Value = 1 Then
ActiveSheet.Shapes("rt5").Visible = True
Else
ActiveSheet.Shapes("rt5").Visible = False
End If

If ActiveSheet.Range("J13").Value = 1 Then
ActiveSheet.Shapes("rt6").Visible = True
Else
ActiveSheet.Shapes("rt6").Visible = False
End If
...

End Sub
This comment was minimized by the moderator on the site
Good day,
Do you mean you want to display or hide lots of specified shapes based on cells in range J13:AC161 with brief code?
This comment was minimized by the moderator on the site
This works great for me as long as the value entered is a number. I need it to work on letters like A B C etc: when i use letters it works backwards enter A and it hides i need it to be visible when i enter a letter any ideas
This comment was minimized by the moderator on the site
You can use letters instead, you just need to add " to either side. E.g. Me.Shapes("Oval 6").Visible = (Cells(1, 1).Value = "A")
This comment was minimized by the moderator on the site
How about if i want to add two values as the input such as : E.g. Me.Shapes("Oval 6").Visible = (Cells(1, 1).Value = "A" Or "B")?
This comment was minimized by the moderator on the site
Me.Shapes("Rounded Rectangle 2").Visible = (Cells(1, 1).Value = "A" Or Cells(1, 1).Value = "B")
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations