I'm trying to make code that, depending on an integer (which loops from 0 to 4), changes the targeted userform label. I've tried using
Eg
Public placeholderLabel as label
sub test()
if loopInt = 1
set placeholderLabel = userForm1.labelTestA
elseif loopInt = 2 then
set placeholderLabel = userForm1.LabelTestB
End if
placeholderLabel.caption "Woohoo!")
end sub
I've tried userform1.controls.LabelTestA and this did not do anything.
My intention was to be able to loop from 0 to 4 and then depending on the loopInt change 1 of the 5 labels. At this point it would have been way easier for me to just repeat the 5 assignments instead of looping 0 to 4 and changing the placeholders...but I want to understand why it is that my assignments to these userform objects isn't working. Very frustrating!
placeholderLabel.caption "Woohoo!")
is improper. try placeholderLabel.caption = "Woohoo!"
If the name of your control is "myControl" then UserForm1.Controls("myControl")
will get you the object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.