I'm just learning VBA in Excel and have been going through the books,
but I can't find the answer to this.
I'm trying to get control of the visible aspect of OptionButtons made
from the Control Toolbar (ActiveX?).
I have lots of them.
I have written a sub that works but I would like to find out how to
refer to the buttons so I can do this better with a couple of loops.
Here's what I mean.
Sub hideStuff()
If (Worksheets("sheet1").Range("Z 5") > " ") Then
Worksheets("sheet2").OptionBut ton1.Visible = True
Worksheets("sheet2").OptionBut ton2.Visible = True
Worksheets("sheet2").OptionBut ton3.Visible = True
and so on
Else
Worksheets("sheet2").OptionBut ton1.Visible = False
Worksheets("sheet2").OptionBut ton2.Visible = False
Worksheets("sheet2").OptionBut ton3.Visible = False
and so on
end if
end sub
Now I would like to put this in a loop where I could use a string for
the name of the buttons like
Name = "OptionButton" & 1
But then how do I refer to the buttons? I've tried everything I can
think of.
Worksheets("sheet2").OptionBut ton(Name).Visible = True
Can someone tell me what the piece is that identifies the object type
in the line above?