+ Reply to Thread
Results 1 to 7 of 7

Thread: dropdown list/ComboBox

  1. #1
    Registered User
    Join Date
    11-15-2010
    Location
    Norway
    MS-Off Ver
    Office 11
    Posts
    17

    dropdown list/ComboBox

    Hello.

    I want to make a dropdown list in a UserForm.

    I have created the drop down list, but I do not know how to get data from the excel sheet in the list and how to find out which of the numbers in the list, the user has clicked.

  2. #2
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Re: dropdown list/ComboBox

    There are a couple of ways to fill your Combobox.

    First there is a property called "row source" that needs a range to point it to the data that you want to use in the Combobox. (Easiest)

    http://img.photobucket.com/albums/v3...0/Untitled.jpg





    Second you can leave the row source blank and use the .AddItem method where you can fill the Combobox each time the UserForm is initiated. (always has the updated info)

    ....and there is another 3rd way that is escaping me at the moment, maybe one of the other forum members will chime in and jog my memory.


    EDIT:can you post an example workbook?, it helps someone like me who isn't all that versed in VBA to figure out what is going on with the problem that you describe.
    Last edited by jwright650; 01-26-2011 at 07:51 AM. Reason: added picture of Row Source in Properties Window
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  3. #3
    Registered User
    Join Date
    11-15-2010
    Location
    Norway
    MS-Off Ver
    Office 11
    Posts
    17

    Re: dropdown list/ComboBox

    "]can you post an example workbook?, it helps someone like me who isn't all that versed in VBA to figure out what is going on with the problem that you describe"
    Attached Files Attached Files

  4. #4
    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: dropdown list/ComboBox

    Take a look at this
    Attached Files Attached Files
    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)

  5. #5
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Re: dropdown list/ComboBox

    Here is yo0ur file with the row source filled in (A1:A5) - see properties window, scroll down to "row source"

    Also added some code to your command button to enter the number chosen into cell B1
    Attached Files Attached Files
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  6. #6
    Registered User
    Join Date
    11-15-2010
    Location
    Norway
    MS-Off Ver
    Office 11
    Posts
    17

    Re: dropdown list/ComboBox

    First, thanks for the great help!
    I have another question.
    Now I have changed a bit on the file RoyUK made, and I want the text to come in the dropdown list, but number to the right of the text is pasted into cell C1 (so if you choose "One"in the dropdown list, it should write "1 "C1
    Attached Files Attached Files

  7. #7
    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: dropdown list/ComboBox

    Try this, I've amended the code to display two columns in the combobox & use the ComboBox's List property

    Or you can use the same settings as the first example
    Private Sub CommandButton1_Click()
        With Me.ComboBox1
            Range("C1").Value = Cells(.ListIndex + 1, 2).Value
        End With
    End Sub
    Attached Files Attached Files
    Last edited by royUK; 01-26-2011 at 12:49 PM.
    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)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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