Method 1 – Create a Dataset with Proper Parameters
Create your list. We created a “List of Food” column with 8 items and another column with “Quantity Sold.” We created a ComboBox with the list of the first column. As a result, our dataset looks like this:
Method 2 – Open Microsoft Visual Basic Window
Open the Microsoft Visual Basic window.
- Go to the Developer tab.
- Press on Visual Basic from the ribbon.
- Apply the keyboard shortcut Alt+F11 to open the window.
- The Microsoft Visual Basic window will appear.
Method 3 – Create ComboBox
Insert a new Userform and create a ComboBox.
- Go to the Insert tab and select Userform.
- A Userform window will open with a Toolbox. From the Toolbox, click Combobox.
- Drag your cursor to create a ComboBox of your desired size.
- Double-click inside the combobox to open a window to write codes.
Method 4 – Copy-Paste VBA Code
Need a VBA code to select the first item from the ComboBox.
- Write the following VBA code or copy it from below and paste it into the window.
Private Sub ComboBox1_Change()
Me.ComboBox1.AddItem "Cookies"
Me.ComboBox1.AddItem "Chocolate"
Me.ComboBox1.AddItem "Coffee"
Me.ComboBox1.AddItem "Yogurt"
Me.ComboBox1.AddItem "Donuts"
Me.ComboBox1.AddItem "Croissant"
Me.ComboBox1.AddItem "Waffles"
Me.ComboBox1.ListIndex = 0
End Sub
- If you want to change the name of the Userform, go to Properties and change the Caption.
Method 5 – Run VBA Code
Run the VBA code.
- Click on the Run Macro button, or press F5 on your keyboard to run the code.
- The worksheet will open, and you will find a ComboBox.
- Type anything in the combobox. It will just show the first item on the list.
- If you try to select other items, it will still show the first item.
- Insert the Userform instead of Module in the Microsoft Visual Basic window.
- Write the item you want to be selected in the first place in the VBA code.
Download Practice Workbook
Download this practice workbook while you are reading this article.
Related Articles
- How to Create a Searchable ComboBox with VBA in Excel
- How to Use ListFillRange Property of ComboBox in Excel
- How to Clear Items from VBA ComboBox in Excel