using a variable for the label numbers


Posted by Blake Rubin on February 11, 2002 2:00 PM

i am using a userform to display a list of errors on an excel spreadsheet, i have 10 label on the form. I want to have the captions of the labels to list the errors in the order that they come up in the macro. I tried a bunch of different ways, but i cant get the syntax right, im not farmiliar with the set statement b/c i think thats what i need to use, like:

x=x+1
set labeler="userform1.label" & x
labeler.caption="error"

any help on how to do this is appreciated, thanks.



Posted by DRJ on February 11, 2002 2:07 PM

Hi

I dont think you can reference it like that, I have tried myself to no avail. What I ended up doing was this, it should work for you too.

You have an error so then make x=x+1

Then

userform1.controls(x).caption = "Error"

Now in this case it would assume that control(x) in this case 1 is the one that you want, but lets say the labels you want are controls 10-20 then

userform1.controls(x+9).caption = "Error"

Would be what you would use.

If you want a quick way to findout what all the controls are then do this

For x = 1 to userform1.controls.count
sheets("Sheet1").range("a65536").end(xlup).offset(1,0).value = userform1.controls(x).name
next x


HTH

DRJ