+ Reply to Thread
Results 1 to 10 of 10

Where to populate Combo Boxes

  1. #1
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Where to populate Combo Boxes

    I understand that in order to populate a combo box, you must do like so:

    comboBox1.AddItem"1"


    etc


    However i am not sure where to put this code. I have a combo box on a form. This form is pulled up by a button I have on my worksheet where the macro is assigned to it. Is there a way to set it upon the creation of the form that is being brought up (upon click of the button)?

    Thanks!
    Last edited by andrew c.; 06-14-2011 at 05:58 PM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Where to populate Combo Boxes

    As an example which you would put in the code for the form.

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Where to populate Combo Boxes

    Thanks!

    So the form I am using is called Activities. Would I put this code where all the subs go for activities or would I put this in a module? I tried it in the activities and in my main module and it still isn't populating the combo box? Any suggestions?

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Where to populate Combo Boxes

    Right click the form Activities, select "View Code" and then insert it there.

    Regards
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Where to populate Combo Boxes

    In the VB Editor double click on the UserForm to open the code module for the form paste the code there
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Where to populate Combo Boxes

    Guys this still doesn't work and I'm not sure why. I put this in the Activities worksheet code

    Please Login or Register  to view this content.
    My combo box is named ComboBox1, and the sheet is Activities. I'm just trying to get something to default populate it but I can't.
    Last edited by andrew c.; 06-14-2011 at 01:11 PM.

  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: Where to populate Combo Boxes

    Hi andrew c.

    Attached is a working example for you to examine. It demonstrates both the ComboBox and the ListBox.
    Attached Files Attached Files
    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.

  8. #8
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Where to populate Combo Boxes

    Thank You Very Much!

    I had exactly what you put... still wasn't working. So I deleted the form and re-did it and it worked? Who knows why that works sometimes.

  9. #9
    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: Where to populate Combo Boxes

    Hi andrew c.

    Glad to help...I'm a visual learner...examples ALWAYS help me.

    You probably didn't have this code
    Please Login or Register  to view this content.
    So, your ComBox may well have been populated but you didn't see it.
    Last edited by jaslake; 06-14-2011 at 06:07 PM.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Where to populate Combo Boxes

    or:
    In post #6 you have
    Please Login or Register  to view this content.
    quote;
    and the sheet is Activities
    unquote

    Might that be the problem? You referenced the sheet name instead of the userform name.

+ 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