Shapes, Userform and Visible

  • Thread starter Thread starter Joel Mills
  • Start date Start date
J

Joel Mills

I have 4 buttons assigned to a userform within a frame. I have four shapes
that are not visible, and want the usere to be able to select a button and
make one of the shapes visible. When I click any of the buttons the shape
becomes visible. But when i select two or more they all become visible.
below is the code for one of the buttons. How do I modify the code to only
allow for one shape to be visible upon slection of the button?

Joel Mills

Sub PLANNEDLegend()
ActiveSheet.Shapes("LEGEND PLANNED").Visible = True
End Sub
 
Vasant thanks for your help. Below is the revised code incase others might
find it useful. I followed your advice and set each of the shapes where the
one I want to be visible true and all the others false.

Sub PLANNEDLegend()
ActiveSheet.Shapes("LEGEND PLANNED").Visible = True
ActiveSheet.Shapes("LEGEND PE").Visible = False
ActiveSheet.Shapes("LEGEND ELPE").Visible = False
ActiveSheet.Shapes("LEGEND ELE").Visible = False
End Sub
 
You might think it's overkill, but I usually end up with a construct
like below. In the long run I find it's easier to debug and maintain.
It's especially true if you end up with a lot of conditionally visible
or enabled controls.

Const PLANNED_SHAPE As Integer = 1
Const PE_SHAPE As Integer = 2
Const ELPE_SHAPE As Integer = 3
Const ELE_SHAPE As Integer = 4

Sub Button1_Click()
ShowShape(PLANNED_SHAPE)
End Sub

Sub Button2_Click()
ShowShape(PE_SHAPE)
End Sub

Sub Button3_Click()
ShowShape(ELPE_SHAPE)
End Sub

Sub Button4_Click()
ShowShape(ELE_SHAPE)
End Sub

Sub ShowShape(ByVal id as Integer)
ActiveSheet.Shapes("LEGEND PLANNED").Visible = (PLANNED_SHAPE = id)
ActiveSheet.Shapes("LEGEND PE").Visible = (PE_SHAPE = id)
ActiveSheet.Shapes("LEGEND ELPE").Visible = (ELPE_SHAPE = id
ActiveSheet.Shapes("LEGEND ELE").Visible = (ELE_SHAPE = id)
End Sub
 
Thanks for the reply. I'm trying to teach myself VBA by writing a program
for myself and co-workers use. I appreciate the effort you placed in this
post. I'll try it out, and I am sure, that I can apply it or portions of it
in this project.

Joel Mills
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top