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

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

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:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, 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!
officetab bottom
Say something here...
symbols left.
You are guest
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.
    Gus · 6 months ago
    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"))
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      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
  • To post as a guest, your comment is unpublished.
    Piaget · 1 years 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 · 1 years 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 · 3 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 · 1 years 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")
      • To post as a guest, your comment is unpublished.
        faisalzainol96 · 8 months ago
        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")?
        • To post as a guest, your comment is unpublished.
          bob · 2 months ago
          Me.Shapes("Rounded Rectangle 2").Visible = (Cells(1, 1).Value = "A" Or Cells(1, 1).Value = "B")