Consulting

Results 1 to 4 of 4

Thread: Solved: user form control problem - using names in loop

  1. #1
    VBAX Regular bodhi's Avatar
    Joined
    Nov 2005
    Posts
    13
    Location

    Solved: user form control problem - using names in loop

    Hi everyone,

    I do not know if what i am trying to do is possible but if it is, i am sure there is a very simple answer out there. Here's what i want to do:

    I have created a user form and added several command buttons to it at design time. Let's say their names are cmdBtn1, cmdBtn2, ... , cmdBtn9.

    I want to be able to use the names in a loop to assign a caption to the relative command button.

    eg. cmdBtn(count).caption = range("A" & count).value

    is there any way to concatenate the first part of the name "cmdBtn" with a variable integer "count" and use it in the form above?

    maybe there is a simpler way around this...????


  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Something like this, perhaps?

    [VBA] For Counter = 1 To 9
    Me.Controls("cmdBtn" & Counter).Caption = Range("A" & Counter)
    Next
    [/VBA]

  3. #3
    VBAX Regular bodhi's Avatar
    Joined
    Nov 2005
    Posts
    13
    Location
    matthewspatrick,

    thanks for that...works perfectly...just what i was after.

  4. #4
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Glad to be of service

Posting Permissions

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