How to turn on Shapes conditionally?
Hi Ken,
Thank you very vrey much for the VBA code. It worked great. It is amazing
how a simple code can have such an impressive result.
Thank you again,
DORI
"Ken Johnson" wrote:
Hi DORI,
If these are the only shapes on your sheet it could be done like
this...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Shp As Shape
For Each Shp In Me.Shapes
Shp.Visible = Range("H10").Value = Shp.Name
Next Shp
End Sub
Before you use the code, position them all where you want them to
appear.
When you type "Box" in H10 only the Box will be visible etc
Before the code will work the way you want you will have to change each
freeform's name. To do that select a freeform then type its new name in
the Name Box on the left side of the Formula Bar, then press Enter
(Don't forget this important press of Enter).
Repeat with each freeform until you have named them all according to
the names you will be typing in H10.
You could also use a data validation dropdown list on H10 to select the
name of the freeform to show.
If you have other shapes on the sheet that you don't want the code to
make invisible, then you will have to extend the code so that those
shapes are skipped. For example say there is a shape named Rectangle 1
that has to remain visible at all times then the code should be changed
to...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Shp As Shape
For Each Shp In Me.Shapes
If Shp.Name < "Rectangle 1" Then
Shp.Visible = Range("H10").Value = Shp.Name
End If
Next Shp
End Sub
Ken Johnson
|