Unselectable items in a Combo Box in an Excel VBA

dunkelme

I have a combo box (in a user form in Excel) whose data source is set of menu items with headers (a named range in a worksheet). Right now, my workaround is to erase these headers (e.g. Main Course, Desserts, Beverages, etc.) but I would still like to know if it's possible to add these unselectable headers so that the end user has distinctions between the different menu items. Any help would be very much appreciated :)

e.g.

Main Courses (**unselectable**)
Roast Beef with Mashed Potato (selectable)
Spicy Spareribs (selectable)
Beef Stroganoff (selectable)
Roast Chicken (selectable)
Desserts (**unselectable**)
Mango Float (selectable)
Brownies (selectable)
Lemon Squares (selectable)
Siddharth Rout

No AFAIK, you can't do that. Below are two alternatives. Take your pick :)

Alternative 1

Deselect the moment user selects the relevant header. For example

Private Sub UserForm_Initialize()
    ComboBox1.Style = fmStyleDropDownList
    ComboBox1.AddItem "---  Main Courses ---"
    ComboBox1.AddItem "Roast Beef with Mashed Potato"
    ComboBox1.AddItem "Spicy Spareribs"
    ComboBox1.AddItem "---  Desserts  ---"
    ComboBox1.AddItem "Mango Float"
    ComboBox1.AddItem "Brownies"
End Sub

Private Sub ComboBox1_Click()
    Select Case ComboBox1.Value
    Case "---  Main Courses ---", "---  Desserts  ---"
        ComboBox1.Value = ""
    End Select
End Sub

Alternative 2

Use two comboboxes. One for the header and the other for the different menu items. Simply populate the second combobox based on the selection of the first combobox. For example

Private Sub UserForm_Initialize()
    ComboBox1.Style = fmStyleDropDownList
    ComboBox2.Style = fmStyleDropDownList
    ComboBox1.AddItem "---  Main Courses ---"
    ComboBox1.AddItem "---  Desserts  ---"
End Sub

Private Sub ComboBox1_Click()
    ComboBox2.Clear

    Select Case ComboBox1.Value
    Case "---  Main Courses ---"
        ComboBox2.AddItem "Roast Beef with Mashed Potato"
        ComboBox2.AddItem "Spicy Spareribs"
    Case "---  Desserts  ---"
        ComboBox2.AddItem "Mango Float"
        ComboBox2.AddItem "Brownies"
    End Select
End Sub

Also to be on a safer side, use the ComboBox1_Change event.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel VBA adding items to combo box without repeated items

From Dev

Excel VBA adding items to combo box without repeated items

From Dev

Combo Box in VBA Excel

From Dev

Excel VBA: Looping through a combo box's items from another user form

From Dev

Assigning values to Combo box in excel VBA

From Dev

Assigning values to Combo box in excel VBA

From Dev

Excel VBA: how to store combo box current value to cell

From Dev

Activate combo-box action on select value using Excel VBA

From Dev

Excel VBA Replace data validation lists with combo box

From Dev

How to send these items in the combo box

From Dev

Set items to Combo Box in JAVA

From Dev

VBA: Initialize Combo Box in worksheet

From Dev

Combo box custom items and data bound items

From Dev

Combo box custom items and data bound items

From Dev

Excel Combo Box Refresh Dropdown?

From Dev

How to add BOTH static values and records from a table as list items to a combo box in VBA

From Dev

How to Open Drop down (combo items) of Combo Box on KeyDown Event?

From Dev

How to Open Drop down (combo items) of Combo Box on KeyDown Event?

From Dev

Adding items to combo box in a table in netbeans

From Dev

How to add items from combo box into array

From Dev

How to add data table items in a combo box?

From Dev

Edit Win32 combo box items

From Dev

Adding items to combo box in a table in netbeans

From Dev

Selected value in combo box to open another worksheet in Excel VBA/User form

From Dev

Excel VBA: Why does combo box shows only one item in the list?

From Dev

Scraping website data with options in combo box VBA

From Dev

VBA Add combo box values together

From Dev

Adding items from a database to a combo box and a text box

From Dev

Excel Combo box conditional If statement to detect blank

Related Related

  1. 1

    Excel VBA adding items to combo box without repeated items

  2. 2

    Excel VBA adding items to combo box without repeated items

  3. 3

    Combo Box in VBA Excel

  4. 4

    Excel VBA: Looping through a combo box's items from another user form

  5. 5

    Assigning values to Combo box in excel VBA

  6. 6

    Assigning values to Combo box in excel VBA

  7. 7

    Excel VBA: how to store combo box current value to cell

  8. 8

    Activate combo-box action on select value using Excel VBA

  9. 9

    Excel VBA Replace data validation lists with combo box

  10. 10

    How to send these items in the combo box

  11. 11

    Set items to Combo Box in JAVA

  12. 12

    VBA: Initialize Combo Box in worksheet

  13. 13

    Combo box custom items and data bound items

  14. 14

    Combo box custom items and data bound items

  15. 15

    Excel Combo Box Refresh Dropdown?

  16. 16

    How to add BOTH static values and records from a table as list items to a combo box in VBA

  17. 17

    How to Open Drop down (combo items) of Combo Box on KeyDown Event?

  18. 18

    How to Open Drop down (combo items) of Combo Box on KeyDown Event?

  19. 19

    Adding items to combo box in a table in netbeans

  20. 20

    How to add items from combo box into array

  21. 21

    How to add data table items in a combo box?

  22. 22

    Edit Win32 combo box items

  23. 23

    Adding items to combo box in a table in netbeans

  24. 24

    Selected value in combo box to open another worksheet in Excel VBA/User form

  25. 25

    Excel VBA: Why does combo box shows only one item in the list?

  26. 26

    Scraping website data with options in combo box VBA

  27. 27

    VBA Add combo box values together

  28. 28

    Adding items from a database to a combo box and a text box

  29. 29

    Excel Combo box conditional If statement to detect blank

HotTag

Archive