Declare Variables for CheckBos Object


Posted by John Bennito on January 31, 2002 10:44 AM

In a UserForm I have about 25 checkboxes that I have named CB1 through CB25. When I call up the UserForm I would like the Userform_activate code to check which Columns 1 through 25 on the worksheet have been hidden on the worksheet. If they are hidden, I would like to check the box (set value of checkbox to "true").

I proposed to do it in a loop as follows.

For x = 1 to 25
if activesheet.column(x).width = 0 then
mm = "Userform.cb" & x
mm.value = true
else
mm = "Userform.cb" & x
mm.value = False
end if
Next x

I have tried declaring "mm" as an object varible and used the set command also but to no avail.

However the code only works if I hardcode the name of the checkbox - it does not like the variable x. Is there a way to define the variable - or will I have to hard code the names and not do them in a loop.

Please advise.

Thanks

Posted by Mark O'Brien on January 31, 2002 11:16 AM

Quick example of what I've done. I've got a textbox on my userform called "TextBox" one. You can modify this to work with your code. It also saves the need to set an object variable:

Dim MyName As String

MyName = "TextBox" & 1
Me.Controls(MyName).Text = "Hi"



Posted by John Bennito on January 31, 2002 11:48 AM

Mark

That worked real good. Saved me from writing a lot of code.

Thanks

John