Search code examples
vbaexcel

Get position (in number) of selected item in dropdown list


In a dropdown list I have a few items. Can I, when I select an item, get the position of that item in the list as a number?


Solution

  • If you are using a list or combo box, ListIndex would seem to be what you are after.

    VB Help for ListIndex property: Returns or sets the index number of the currently selected item in a list box or combo box. Read/write Long. Remarks. You cannot use this property with multiselect list boxes.

    If nothing is selected, ListIndex's value is -1. If memory serves, it is a zero based index.

    ListIndex cannot be set at design time so it is not listed in the properties window.

    When entering your code, type the list box name then dot and the editor displays all the available properties. Scroll down the list, note any that look interesting, then look them up.