How to Populate a Combo Box With Specified Data on Workbook Open?


Combination boxes are effective tools that let users choose items from a list that has already been defined. When a worksheet is opened, populating a combo box with specific data automatically can substantially improve the user experience and speed up data entering procedures.

In this article, we'll look at how to implement this capability in Excel step-by-step. This guide will equip you with the skills necessary to automatically fill a combo box with supplied data, regardless of your level of Excel proficiency.

Populate a Combo Box With Specified Data on Workbook Open

Here we will add the VBA code to the workbook to complete the task. So let us see a simple process to know how you can populate a combo box with specified data on a worksheet open in Excel.

Step 1

Consider an Excel sheet where you have a combo box similar to the below image.

First, right-click on the sheet name and select View code to open the VBA application.

Right Click > View Code.

Step 2

Then double-click on ThisWorkbook and copy the below code into the text box.

Code

Private Sub Workbook_Open()
   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

In the code, ComboBox1 is the name of the combo box.

Step 3

Then close the VBA using Alt + Q. Then save the sheet as macro enabled template and close Excel.

Step 4

Then reopen the sheet and click on Enable Content to complete the task.

Then you can see that the combo box will be populated with the specified data. This is how you populate a combo box with specified data when a workbook is open.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can populate a combo box with specified data on a worksheet open in Excel to highlight a particular set of data.

Updated on: 07-Sep-2023

45 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements