Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Variable control name (Excel 2002)

    Hi all,

    I'm not sure if it can be done, but I have a need to display 30 labels on a Userform. I have named these label controls , L1w1, L1w2, L1w4, and so on, what I would like to do is loop thru them to dynamically place a caption in each one based on the control name. What I would like to know is is it legal to do this, or is there another way around naming a control dynamically?

    Thanks,
    Darryl.

    option explicit

    dim i as integer
    dim label1 as integer
    dim labelposition as integer
    dim theLinlabel as string
    dim theWinlabel as string
    dim thename as string
    dim z as integer
    i=1
    thename=theLinlabel & i & theWinlabel & i

    userform1.thename.caption=somevalue <---is this allowed somehow?

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable control name (Excel 2002)

    For i=1 to 20
    Me.Controls("L1w" & i).Caption="Caption for label " & i
    Next
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Variable control name (Excel 2002)

    Thanks!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •