+ Reply to Thread
Results 1 to 6 of 6

userform variable

  1. #1
    Registered User
    Join Date
    07-14-2012
    Location
    Walkerton, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    29

    userform variable

    I'm trying to reference a label within a form using a variable, then assigning a range reference for the caption of that label.

    My userform is named "frmDriverWatch"

    dname i the variable I'm having trouble with. How do I reference it properly within this code?

    dnum = dnum + 1
    dname = "driver" & dnum
    refnum = refnum + 1

    frmDriverWatch.dname.Caption = Sheets("Drivers").Range("$o$" & refnum)

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: userform variable

    Hi,

    Try

    frmDriverWatch.Controls(dname).Caption = Sheets("Drivers").Range("$o$" & refnum)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-14-2012
    Location
    Walkerton, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: userform variable

    wow - is there a way to learn all these commands, or is it trial and error.

    Thanks a bunch

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: userform variable

    Hi,

    It doesn't have to be trial and error although that's often the last resort.

    Most Excel VBA/Macro text books cover all this sort of stuff. There are many available, just search amazon.

  5. #5
    Registered User
    Join Date
    07-14-2012
    Location
    Walkerton, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: userform variable

    thanks a bunch - problem solved!

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: userform variable

    Quote Originally Posted by LRFT View Post
    wow - is there a way to learn all these commands, or is it trial and error.

    Thanks a bunch
    One huge asset is the on-board Object Browser.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1