Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to hide or unhide a certain shape based on specified cell value in Excel?

Actually, a certain shape can be hidden or unhidden based on the value of a specified cell. The following method can help you.

Hide or unhide a certain shape based on specified cell value with VBA code


arrow blue right bubble Hide or unhide a certain shape based on specified cell value with VBA code


For example, you want to unhide a certain shape when entering number 1 into cell A1, or hide this shape if cell A1 is other values. Please run the following VBA code to achieve it.

1. Right click the sheet tab which contains the shape you will hide or unhide, then click View Code from the right-clicking menu.

2. Then the Microsoft Visual Basic for Applications window pops up. Please copy and paste the below VBA code into the Code window.

VBA code: Hide or unhide a certain shape based on specified cell value

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

Notes: In the code:

1) Row=1 and Column=1 indicate the specific cell which is located in row one and column one, Cells(1, 1) is the corresponding cell A1.

2) Value = 1, the number 1 is the specific value that you want to show the shape based on.

3) “Oval 6” is the name of the certain shape.

You can change them based on you need.

3. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.

From now on, when entering number 1 into cell A1, the shape “Oval 6” is unhidden. But if you enter other value such as number 2 into the cell A1, the shape “Oval 6” is hidden immediately.


arrow blue right bubbleRelated articles:


Recommended Productivity Tools for Excel

kte tab 201905

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Piaget · 11 months ago
    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
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      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?
  • To post as a guest, your comment is unpublished.
    A Webb · 2 years ago
    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
    • To post as a guest, your comment is unpublished.
      C Aubrey · 6 months ago
      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")