• Labels in Code (xp)

    Author
    Topic
    #437905

    I have some labels named Label1through Label20 on a userform. Is there a way to refer to these labels dynamically from within code using a variable? For example, if the variable is X=2, say, I want to change the BackColor property of Label2 to a different value.

    TIA

    Viewing 0 reply threads
    Author
    Replies
    • #1042544

      Yes, you can use

      Me.Controls(“Label” & X).BackColor = vbGreen

      if the code is in the userform module, or

      UserForm1.Controls(“Label” & X).BackColor = vbMagenta

      where UserForm1 is the name of the form.

    Viewing 0 reply threads
    Reply To: Labels in Code (xp)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: