+ Reply to Thread
Results 1 to 13 of 13

Populate userform combo box with named dynamic list

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Populate userform combo box with named dynamic list

    Excel 2007 and very new to VBA...

    I have a userform (named "QAReviewForm") with a combobox (named "cboSupName"). I want it to populate with my named range "SupList".

    FYI, the SupList is found on sheet 2, "Administrative Menu" in column E. E1 contains the heading "Supervisors", and my named range formula is

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    My code is has follows:
    Please Login or Register  to view this content.
    When it runs, my form opens and the combobox is there, but nothing appears as options for me to select (yes, I have some values in column E).

    Any help is greatly appreciated.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate userform combo box with named dynamic list

    It's always UserForm_Initialize, never formname_Initialize.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Populate userform combo box with named dynamic list

    OK, I get that now...

    I have deleted the Userform_Initialize routine altogether... though I assume it needs to go somewhere?

    But still, my basic problem is that on my QAReviewForm, I intend to have several combo boxes. I was trying to get the first one, Supervisor Name, to populate from the Admin Menu sheet (dynamic range)... eventually, the Employee Name will do the same, and Program # and Location combo boxes will populate from named ranges on the LookupLists sheet.

    I'm sure I'll have more questions and challenges down the road, but right now I'm stuck on this one.

    HeyInKy

    QA Form draft3.xlsm

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate userform combo box with named dynamic list

    You shouldn't have deleted anything.

    All you needed to do was change Private Sub QAReviewForm_Initialize() to Private Sub UserForm_Initialize().

    As for populating comboboxes based on selections in other comboboxes that's kind of a different topic.

  5. #5
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Populate userform combo box with named dynamic list

    The Userform_Initialize routine goes in the UserForm which is actually a Class Module with a GUI.
    Assuming the relationships between the different lists are taken care of by the dynamic, named ranges, put the name of the named range, as a text string, in the RowSource property of the control to populate the List.


    Sent from my iPhone using Tapatalk

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate userform combo box with named dynamic list

    Put this code in the userform module.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Populate userform combo box with named dynamic list

    The other option, assuming the named range has Workbook scope, is like this...
    Please Login or Register  to view this content.
    I'd be interested in Norie's view, but as far as I know RowSource works ok.


    Sent from my iPad using Tapatalk

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate userform combo box with named dynamic list

    coolblue

    Populating with RowSource can cause problems later, mainly because it's kind of a 2 way thing.

  9. #9
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Populate userform combo box with named dynamic list

    Quote Originally Posted by Norie View Post
    Put this code in the userform module.
    Please Login or Register  to view this content.
    This answer worked great. Thanks @ Norie. You're awesome!

  10. #10
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Populate userform combo box with named dynamic list

    Quote Originally Posted by Norie View Post
    coolblue

    Populating with RowSource can cause problems later, mainly because it's kind of a 2 way thing.
    Ok, can you give an example?
    When you say it causes problems later, what circumstances are you talking about?

    My understanding is that it's one way: data comes in from RowSource and out (if you click on another control) to ControlSource.

    I mean, the List structure is nice... being a nice juicy variant array and I use it for reading and setting the Selection (I've noticed that .Value is definitely buggy in ListBoxes, so I avoid that one and ControlSource is not very responsive)...
    But it's tempting to leave the upload to native code in RowSource.

    I'm just curious to bottom out what works and why.


    Sent from my iPhone using Tapatalk

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate userform combo box with named dynamic list

    Try this when you've populated using RowSource.
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Populate userform combo box with named dynamic list

    Quote Originally Posted by Norie View Post
    Try this when you've populated using RowSource.
    Please Login or Register  to view this content.
    OK, thanks for explaining Norie.

    For me its not an issue if I leave the management of the lists to the dynamic named ranges.
    The only problem with that is that the named range in RowSource is not resolved dynamically in the UserForm.
    But, that can be handled with patterns like this in the UserForm Module...

    Please Login or Register  to view this content.
    initLists just sets and re-sets the RowSource of the applicable controls and the WorkBook event can be focused in on the applicable ranges if required.
    Its very fast and no fuss because initLists only has to write a few strings and then all of the detailed works is taken care of in native code.
    Last edited by coolblue; 08-24-2014 at 11:32 AM.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate userform combo box with named dynamic list

    Can't be bothered.
    Last edited by Norie; 08-28-2014 at 05:25 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Named range to populate a Combobox in userform
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2015, 09:57 PM
  2. [SOLVED] User form combo box to look up a dynamic named range
    By cobwebs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2014, 07:24 AM
  3. [SOLVED] Using dynamic named range as row source for combo box
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 12-20-2013, 09:58 PM
  4. [SOLVED] Adding dynamic named ranges to combo boxes in userform
    By Spritz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-04-2013, 09:45 AM
  5. Populate a textbox in a userform using multiple selections from a combo box
    By kksf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2013, 10:59 AM

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