+ Reply to Thread
Results 1 to 12 of 12

Thread: UserForm ComboBox problems

  1. #1
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    19

    UserForm ComboBox problems

    Hi all,

    I don't know why my last post got deleted, so I'm sorry if I did something wrong...

    I have done a bunch of research on this subject by reading through the posts here etc, but no matter what I try, it doesn't seem to work.

    Basically, I am writing a macro in Excel where when you click a specific button, a UserForm appears asking for data from the user. One of the items is a ComboBox. In the ComboBox, all I want is one selection to be "Yes" and the other to be "No", but no matter what I do, I can't seem to populate these options in my ComboBox.

    I have tried things like ComboBox1.AddItem "Yes" and putting that in the Form_Initialize() method, as well as several other things. Does anybody have any idea what I might be doing wrong?

    Thanks for the help!!

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: UserForm ComboBox problems

    Try
    Private Sub UserForm_Initialize()
    Me.ComboBox1.List = Array("Yes", "No")
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: UserForm ComboBox problems

    Hi Roy,

    I saw that you did respond to my last post, so thanks for replying again. I have tried your suggestion, but my ComboBox still appears to be empty when I click the down arrow attached to its right...

  4. #4
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: UserForm ComboBox problems

    Does anyone have any idea why I'm still having problems pre-populating my combo box with a "Yes" and "No" option? Is there a setting I need to select in Excel maybe?

    Thanks for the help!

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: UserForm ComboBox problems

    Roy's code will work assuming the combobox is called combobox1 and that you didn't alter anything else.

  6. #6
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: UserForm ComboBox problems

    Open the attachment.
    Enable macros.
    Attached Files Attached Files



  7. #7
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: UserForm ComboBox problems

    Thanks for your inputs guys... I have tried both of your suggestions, and still my combobox is blank when I open it...

    My combobox is spelled correctly, I am calling it appropriately in the Initialize() method, and I even tried snb's code that you placed here. I am still at a loss for why it won't work...

  8. #8
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: UserForm ComboBox problems

    Hi,

    It could be a number of things. So that we're not guessing, I think the best thing would be for you to attach your workbook to the thread so we can see it for ourselves.
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  9. #9
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: UserForm ComboBox problems

    Hi guys,

    Attached is my spreadsheet. After enabling macros, to launch the form just push the button you see on the worksheet. The form will appear. The "Active?" label is next to the combobox in question.

    Thanks very much!
    Attached Files Attached Files

  10. #10
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: UserForm ComboBox problems

    Change the name of this sub:
    Private Sub EnterNewClientForm_Initialize()
    To this:
    Private Sub UserForm_Initialize()
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  11. #11
    Registered User
    Join Date
    07-22-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: UserForm ComboBox problems

    Thanks so much Colin! That did the trick. I had no idea that I couldn't use the name that I specifically gave to the UserForm, and had to actually put "UserForm". This is definitely why I was getting confused. I saw all of these examples online, and took that as being a variable-like name.

    Thanks again all!

  12. #12
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: UserForm ComboBox problems

    No problem. Above the code module you should see two dropdown boxes. When you want to create an event handler within a class module, you can pick the relevant class from the top left dropdown box (say, Userform, CommandButton1 etc....). You can then go to the right hand dropdown box and choose which event you want to handle (it will give you a list of available event handlers for that class). When you do this, the event handler procedure shell will be automatically placed in the code module for you.
    Attached Images Attached Images
    Last edited by Colin Legg; 07-25-2011 at 12:42 PM. Reason: added picture
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

+ 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.2.0