Excel VBA ComboBoxes – 4 Examples

How to Add a ComboBox in Excel

This is the sample dataset.

Sample Dataset to Add VBA ComboBox Value

Steps:

  • Go to the Developer tab >> Insert >> Combo Box (ActiveX Control option).

Insert a VBA ComboBox to Work with Value

  • Drag an area for the Combo Box in the Excel file.

A combo box will be displayed.

ComboBox in Excel

 


Example 1 – Adding Values as Single Inputs

Enter the employees’ names (displayed in B5:B9):

Steps:

  • Double-click the combo box.

Double Click on ComboBox to Add Value with VBA

  • The code window of VB Editor will be displayed.
  • Enter the following code and press Ctrl + S.

VBA ComboBox Value Code

  • In the Microsoft Excel dialog box, click No.

  • In Save As, choose .xlsm in Save as type:
  • Click Save.

  • Click Run.

Run VBA to Add ComboBox Value

The values are added to the combo box:

ComboBox Output

Read More: How to Add Item to ComboBox with VBA in Excel


Example 2 – Adding Values from a Range

Steps:

  • Click the combo box.
  • Go to the Developer tab and click Properties.

Access Properties Tool

  • In the Properties window, enter B5:B9 in ListFillRange.

Properties Window

The values in B5:B9 are displayed in the dropdown list.

ComboBox Dropdown


Example 3 – How to Remove a ComboBox Value in Excel VBA

Steps:

  • Double-click the combo box and go to the code window.
  • Use the following VBA code and click Run.

Run VBA to Remove ComboBox Value

All values are removed from the dropdown.

Removed ComboBox Values


Example 4 – How to Set a Default ComboBox Value in Excel VBA

To set a default value in D6:

Steps:

  • Choose a name to set as default.
  • Go to the Developer tab >> View Code.

Access View Code Tool

  • Enter the VBA code below and save the file.
  • Click Run.

Run VBA to Set Default ComboBox Value

The selected name (Sarah) is displayed in D6.

  • Change the employee’s name and you will still see the previous name in D6 by default.

Default ComboBox Value

 

Note: 

If you want to change the default value in D6, select a name and run the code again.


Download Practice Workbook

Download the practice workbook.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Tanjim Reza
Tanjim Reza

Md. Tanjim Reza Tanim, a BUET graduate in Naval Architecture & Marine Engineering, contributed over one and a half years to the ExcelDemy project. As an Excel & VBA Content Developer, he authored 100+ articles and, as Team Leader, reviewed 150+ articles. Tanim, leading research, ensures top-notch content on MS Excel features, formulas, solutions, tips, and tricks. His expertise spans Microsoft Office Suites, Automating Finance Templates, VBA, Python, and Developing Excel Applications, showcasing a multifaceted commitment to the... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo