How to populate a combo box with specified data on Workbook open?
Normally, you can fill a combo box (ActiveX Control) with a certain range of cell data by entering the cell references into the ListFillRange field of the combo box properties. If you want to populate a combo box with specified data directly without manually specifying its properties, the method in this article can help you.
Recommended Excel Productivity Tools
This method can help you populate a combo box with specified data directly on workbook open. Please do as follows.
1. Press the Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, double-click ThisWorkbook in the left pane to open the ThisWorkbook code editor. And then copy below VBA code into it. See screenshot:
VBA code: populate a combo box with specified data on workbook open
Private Sub Workbook_Open() 'Updated by Extendoffice 2018/1/30 With Sheet1.ComboBox1 .Clear .AddItem "Select a Fruit" .AddItem "Apple" .AddItem "Banana" .AddItem "Peach" .AddItem "Pineapple" .AddItem "Watermelon" .Text = .List(0) End With End Sub
1). ComboBox1 is the name of the combo box you will fill data, and this combo box locates in Sheet1. Please change them as you need.
2). And replace the data in the code with your needed one.
3. Save the workbook as Excel Macro-Enabled Workbook format and close it.
4. Reopen the workbook, you will see the combo box has been populated with specified data as below screenshot:
- How to copy Combo Box value to active cell in Excel?
- How to display date format in combo box output in Excel?
- How to prevent or disable typing in a combo box in Excel?
- How to populate Combo Box with data of Named Range in Excel?