Show Shapes Based on Cell Value

simbk

New Member
Joined
Jan 14, 2015
Messages
3
[h=2]
icon1.png
Show Shapes Based on Cell Value[/h]
Advertisement


I want to show and hide shapes on a sheet based on the cell value >1. If cell A1 = 1 the shape should be visible and for value is 0, the shape should be hidden. I thought this would be fairly straight forward but the following code is not working.

Private Sub Worksheet_Calculate()
If Range("A1").Value = 1 Then
ActiveSheet.Shapes("Oval 1").Visible = True
Else
ActiveSheet.Shapes("Oval 1").Visible = False
End If
If Range("A2").Value = 1 Then
ActiveSheet.Shapes("Oval 2").Visible = True
Else
ActiveSheet.Shapes("Oval 2").Visible = False
End If
End Sub​
 
please use code tags around code (click on # icon above post window and paste code between tags)

This works when any cell is selected
Code:
[I]Private Sub Worksheet_SelectionChange[/I](ByVal Target As Range)
    If Range("A1").Value = 1 Then
       ActiveSheet.Shapes("Oval 1").Visible = True
    Else
       ActiveSheet.Shapes("Oval 1").Visible = False
    End If
    If Range("A2").Value = 1 Then
       ActiveSheet.Shapes("Oval 2").Visible = True
    Else
       ActiveSheet.Shapes("Oval 2").Visible = False
    End If
End Sub


When do you want the macro to trigger?
 
Last edited:
Upvote 0
please use code tags around code (click on # icon above post window and paste code between tags)

This works when any cell is selected
Code:
[I]Private Sub Worksheet_SelectionChange[/I](ByVal Target As Range)
    If Range("A1").Value = 1 Then
       ActiveSheet.Shapes("Oval 1").Visible = True
    Else
       ActiveSheet.Shapes("Oval 1").Visible = False
    End If
    If Range("A2").Value = 1 Then
       ActiveSheet.Shapes("Oval 2").Visible = True
    Else
       ActiveSheet.Shapes("Oval 2").Visible = False
    End If
End Sub


When do you want the macro to trigger?

TQ you , I am a beginner,
 
Upvote 0
How are A1 and A2 getting their values? Is the user manually entering them, or is there a formula?
The answer to that would determine the best place to put this code.

Code:
ActiveSheet.Shapes("Oval1").Visible = (1 <= Range("A1").Value)
ActiveSheet.Shapes("Oval2").Visible = (1 <= Range("A2").Value)
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top