+ Reply to Thread
Results 1 to 6 of 6

Determine Selected Item in a (Userform’s) ComboBox

  1. #1
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Determine Selected Item in a (Userform’s) ComboBox

    Q1: Is it possible to determine if the user selected an item from the ComboBox list?
    While ComboBox1.ListIndex is greater than -1 when something from the list is selected, it is also greater than -1 when something is typed in.

    Q2: Is it possible to determine if the user typed something in and pressed “Enter”? How do I know the user is done typing? If there is no way to determine this, I guess one needs to add a button, yes?

    Q3: Is it possible to determine if the item typed in is an item from the ComboBox list?

    Any help will be appreciated!

    Steven Craig Miller
    Last edited by StevenM; 03-07-2012 at 09:08 AM.

  2. #2
    Registered User
    Join Date
    03-07-2012
    Location
    Russia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Determine Selected Item in a (Userform’s) ComboBox

    A1. When something is selected, ListIndex property is greater than -1.
    A2. If Value property is not empty, then user has typed something in (check with "If IsEmpty(cmb.Value)...").
    A3. Set "AutoWordSelect=True".

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Determine Selected Item in a (Userform’s) ComboBox

    Please Login or Register  to view this content.
    I've tried both: If ComboBox1.ListIndex > -1 Then MsgBox ComboBox1.Value

    And: If ComboBox1.AutoWordSelect = True Then MsgBox ComboBox1.Value

    But if I type in a single letter, then ListIndex > -1 and AutoWordSelect = True and ComboBox1.Value is not empty.

    For example, there are a number of items in my list which start with a letter 'L'. And if I type the letter 'L' I get (I assume) the first item on the list which begins with a letter 'L'.

    What I want to know is:

    Q1: Did the user select an item from the list?

    Q2: If the user types in a name, is the user done typing?

    Q3: Is Combobox1.Value an item in the ComboBox1.list?

  4. #4
    Registered User
    Join Date
    03-07-2012
    Location
    Russia
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Determine Selected Item in a (Userform’s) ComboBox

    Here is what happens.
    A1. When you set AutoWordSelect to True, then when user types something in and that "something" matches with any of items, then ListIndex becomes greater than -1 (i.e. 0, 1,2 etc.). Thus ListIndex becomes greater than -1 when a) user typed something and that combobox contains that "something" and b) when user explicitly selected item from drop-down.
    A2. Actually, incorrect question. There's no such definition "done typing". Even empty combobox is "done typing".
    A3. "Combobox1.Value" is the same for "Combobox1.List(Combobox1.ListIndex)".

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Determine Selected Item in a (Userform’s) ComboBox

    Why do you need to know this? It would seem to me far simpler to use the exit event of the combobox rather than the change event.
    Good luck.

  6. #6
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Determine Selected Item in a (Userform’s) ComboBox

    Thanks! That is precisely what I needed!

+ 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