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.
Populate a combo box with specified data with VBA code
Populate a combo box with specified data with VBA code
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
Notes:
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:
Related articles:
- 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?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
