+ Reply to Thread
Results 1 to 8 of 8

Looping through object names

  1. #1
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Looping through object names

    Hi, I have the following code where I have a lot of objects (labels and combo boxes) on a userform which I want to make enable/disabled. My intial code is supposed to make them all diasbled... Here is the long way of doing it...
    Please Login or Register  to view this content.

    To help me with the further coding I have tried to do this as a loop but am struggling. Here is my broken code...
    Please Login or Register  to view this content.


    As you can see I have 2 solutions within the same code I was testing
    The ben variable stuff does seem to work but it is the benefit stuff I would really like to work. Is this kind of thing possible? i.e. frmUW.lblnew" & benefit &".Enabled = False

    Many Thanks
    Last edited by pdauction; 09-22-2011 at 04:46 AM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Looping through object names

    Hello pdauction,

    Here is a code sample that will disable all the labels and ComboBoxes on the UserForm.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Re: Looping through object names

    Many thanks for that usefull coding... Unfortunately it is not all labels and combos that I need to disable (only about half). Apologies that I didn't explain clearer in my opening paragraph. Any help is much appreciated.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Looping through object names

    Please Login or Register  to view this content.



  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Looping through object names

    You can reference the control by name using the Controls collection.

    Something like this.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Looping through object names

    Or you could put the controls that you want to enable/disable in a frame and loop through them

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Re: Looping through object names

    Many thanks both of you. Using the Controls collection has enabled me to solve my problem.

  8. #8
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Looping through object names

    This indeed is very useful information, as I was also looking for something similar and this was just the right recipe..

+ 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