+ Reply to Thread
Results 1 to 7 of 7

How do I loop through combobox objects to add items?

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    50

    How do I loop through combobox objects to add items?

    Hi

    I'm a pretty basic user of VBA and am struggling with the method of looping through objects to make changes.

    I have 12 comboboxes on a userform which I have set to dropdown list and want to populate during the userform initialization.
    Each combobox is called "pt*" where * is a number from 1 - 12.
    I have currently set up my code with 12 lines, one for each combobox to apply the same dropdown list to each of the 12 boxes.
    ie

    Please Login or Register  to view this content.
    (where ptsource contains a range reference on the worksheet)

    I'm interested to learn how to improve my code to loop through 1-12 and apply the rowsource to each combobox.

    I did search through some past questions but could only come up with a method which seemed to step through every combobox on a worksheet rather than userform and in my case, I have two other comboboxes on the userform which I do not want to add this rowsource to, only the "pt*" named comboboxes.

    Would really appreciate some help to understand how to do this as I'm interested to keep improving any code I write.

    Many thanks
    Chris
    Last edited by bodhi808; 03-27-2013 at 11:15 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How do I loop through combobox objects to add items?

    Hi bodhi808

    Probably something like this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    01-28-2013
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    50

    Re: How do I loop through combobox objects to add items?

    Quote Originally Posted by jaslake View Post
    Hi bodhi808

    Probably something like this
    Please Login or Register  to view this content.
    That's perfect, thank you very much for your reply Jaslake.
    I hadn't realised that objects in the form could be manipulated using Me.Control. I will be reading up more on that and experimenting.

    Very much appreciated!
    Chris

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How do I loop through combobox objects to add items?

    You're welcome...glad I could help. Thanks for the Rep.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How do I loop through combobox objects to add items?

    Chris,
    for future reference please read the forum rules-especially rule #8
    thank you :-)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Registered User
    Join Date
    01-28-2013
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    50

    Re: How do I loop through combobox objects to add items?

    Ok, read and understood.
    Are you a member of both communities or did you take a search as I was a new poster?
    Just curious
    Would be good to link to this page in the forum rules too as it answered all the questions I had about cross posting issues. http://www.excelguru.ca/content.php?184

    For reference then, I asked the same question here before realising this was a no no. In my defence I did at least close the question there straight away.

    A poster on the other forum has suggested that rowsource is perhaps not the best method of adding to a combo box. I will enquire why this might be the case.

    Thanks again and apologies for the faux pas.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How do I loop through combobox objects to add items?

    Hi Chris

    You'll find that many of us are members of several Forums and we'll find issues that look familiar. It's a bit frustrating in that we may have addressed the same issue on another Forum. That's the purpose of the Rule...no "Gotcha's"...simple courtesy.

    By the way...there's nothing wrong with this
    rowsource is perhaps not the best method of adding to a combo box
    Depends on what you're trying to do. In this specific application, I believe it's appropriate.
    Last edited by jaslake; 03-27-2013 at 07:26 PM.

+ 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