How to Select First Item from ComboBox Using VBA in Excel

ComboBoxes and listboxes are useful approaches to controlling the consumer experience by confining the values that a consumer can choose to a predefined list. If you start a ComboBox or listbox, the value will be blank by default. But you might need to select the first item in the list. To do that, you can use a simple VBA code. In this article, we will show you how to select the first item from ComboBox using VBA in Excel with easy steps.


How to Select First Item from ComboBox Using VBA in Excel: 5 Easy Step

In this article, we will demonstrate 5 easy steps to select the first item from ComboBox using VBA in Excel. Keep on reading to learn how to do it.


Step 1: Create Dataset with Proper Parameters

In the first step, you will have to create your list. Here, we created a “List of Food” column with 8 items and another column with “Quantity Sold.” Then we created a ComboBox with the list of the first column. As a result, our dataset looks like this:

How to Select First Item from Combobox Using VBA in Excel


Step 2: Open Microsoft Visual Basic Window

In this step, we will open the Microsoft Visual Basic window.

  • First of all, go to the Developer tab.
  • Then press on Visual Basic from the ribbon.
  • You can also apply the keyboard shortcut  Alt+F11  to open the window.

How to Select First Item from Combobox Using VBA in Excel

  • The Microsoft Visual Basic window will appear.


Step 3: Create ComboBox

Now we need to insert a new Userform and create a ComboBox.

  • To do so, go to the Insert tab and select Userform.

Create ComboBox

  • A Userform window will open with a Toolbox. From the Toolbox, click on Combobox.

Create ComboBox

  • Now drag your cursor to create a ComboBox of your desired size.

Create ComboBox

  • Next, double-click inside the combobox to open a window to write codes.


Step 4: Copy-Paste VBA Code

After that, we will need a VBA code to select the first item from the ComboBox.

  • Write the following VBA code or just copy it from below and paste it to 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

How to Select First Item from Combobox Using VBA in Excel

  • If you want to change the name of the Userform, go to Properties and change the Caption.


Step 5: Run VBA Code

Finally, it’s time to run the VBA code.

  • Click on the Run Macro button or just press  F5  on your keyboard to run the code.
  • Now, the worksheet will open and you will find a ComboBox.

How to Select First Item from Combobox Using VBA in Excel

  • Type anything in the combobox. It will just show the first item of the list.

How to Select First Item from Combobox Using VBA in Excel

  • Again, if you try to select other items, it will still show the first item.

How to Select First Item from Combobox Using VBA in Excel

Notes
  • Make sure to 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.

Read More: How to Use ComboBox to Get Selected Item Utilizing VBA


Download Practice Workbook

Download this practice workbook for practice while you are reading this article.


Concluding Remarks

Thanks for making it this far. I hope you find this article useful. Now you know select the first item from combobox using VBA in Excel. Please let us know if you have any further queries and feel free to give us any recommendations in the comment section below.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Alif Bin Hussain
Alif Bin Hussain

Alif Bin Hussain earned a BSc in Civil Engineering from Bangladesh University of Engineering and Technology. As an engineering graduate, he has a deep passion for research and innovation. He loves to play with Excel. In his role as an Excel & VBA Content Developer at ExcelDemy, he not only solves tricky problems but also shows enthusiasm and expertise in handling tough situations with finesse, emphasizing his dedication to delivering top-notch content. He is interested in C, C++,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo