How to use ComboBox in UserForm in Excel VBA Easily with 2 ways

Welcome to Excel Avon

ComboBox in UserForm in Excel VBA

DOWNLOAD USED EXCEL FILE FROM HERE>>

In today’s post, we will tell you how to use ComboBox in UserForm in Excel VBA, In the previous post, we taught you how to use Command Button in UserForm and as we have learned how to insert a label, you will also need to insert a label for a combo. Combobox is the UserForm control in VBA. They differ from text boxes because text boxes only contain text. We allow the user to input any data, but by using a combo box, we limit the user’s desired response type. Thus, the data is in an orderly fashion. This is similar to list data validation in Excel. 

Combo box is similar to the dropdown list we have in excel worksheet. With combo box, we can store pre-defined values or select some category and all in one list so that user can select from the list available from combo box. Combo boxes are commonly used with UserForms to receive user input.

Create ComboBox in UserForm in Excel VBA

Ok, you must know how UserForm is inserted, let’s understand. For how to Use ComboBox in UserForm, we have to go like last time, first go to Developer Tab then click on Visual Basic’s Option as shown in the image below.

sort-data-on-excel-using-VBA

On opening in VBE, you have to go to Insert and then UserForm has to be inserted, as can be seen in the image.

introduction-of-userform

We have inserted the Userform as you can see now, we will do some further work like insert label, text box.

introduction-of-userform.png

We will go to the toolbox, in the tool, we will select the label and then drag it to the userform, then go to the properties of the label and change the caption of the label (Select Standard).

Combobox-inuserform-in-excel-vba

Now we will go to the toolbox, from there we will insert the Combobox as you can see in the image, after that we will customize it accordingly.

Combobox-in-userform-in-excel-vba.png

Now we will go to the worksheet, then now we will select the range of the value which is written and give a new name to that range.

Combobox-in-userform-in-excel-vba.1

Copy the name of the same range and then go to the properties of the combo box in VBE and paste the name of the range in the row source.

Combobox-in-userform-in-excel-vba.2

After pasting in the row source, we will run the code.

Combobox-in-userform-in-excel-vba.3

After running the code, we will get the Userform where we will click on the dropdown button.

Combobox-in-userform-in-excel-vba.4

Now we will go back to VBE and insert a command box in the Userform. And with this you will also rename the command button.

Combobox-in-userform-in-excel-vba.5

Now we will create a condition for show result button if there is value in Combobox in Userform then we will get a message u have selected “value” vbsign.

Private Sub CommandButton1_Click()
If Me.ComboBox1.Value <> "" Then
    MsgBox "You have selected '" & Me.ComboBox1.Value & "'", vbInformation
End If
End Sub

Back we will go to Userform and then run the code.

Combobox-in-userform-in-excel-vba.3

After running the code, we will get the Userform where we will click on the dropdown button. Click the dropdown list and then click the command button.

Combobox-in-userform-in-excel-vba.6

Then we will get the message that You Have Selected.

Combobox-in-userform-in-excel-vba.7

Now we’ll go back to the VBE and go to the Userform, go to the properties of the ComboBox, and then blank the row source.

Combobox-in-userform-in-excel-vba.8

 Then right click in Userform click view code.

Combobox-in-userform-in-excel-vba.9

Now we will open the drop-down list and we will select initialize.

Combobox-in-userform-in-excel-vba.10

Remove private Subroutine. Here an initialize subroutine will be created. Now add item to UserForm ComboBox manually with code.

Private Sub UserForm_Initialize()
Me.ComboBox1.AddItem "1st"
End Sub

Now we will add all the items like this and write the code manually.

Private Sub UserForm_Initialize()
Me.ComboBox1.AddItem "1st"
Me.ComboBox1.AddItem "2nd"
Me.ComboBox1.AddItem "3rd"
Me.ComboBox1.AddItem "4th"
Me.ComboBox1.AddItem "5th"
Me.ComboBox1.AddItem "6th"
Me.ComboBox1.AddItem "7th"
Me.ComboBox1.AddItem "8th"
End Sub

After writing the code we will go to the UserForm form and run the code

Combobox-in-userform-in-excel-vba.3

As you can see the Userform has been created here and items have been added to the Combobox in Userform.

Combobox-in-userform-in-excel-vba.4

Here we will now select any value.

Combobox-in-userform-in-excel-vba.11

After clicking the show button, we will get the message.

Combobox-in-userform-in-excel-vba.12

In this way we can create Combobox in UserForm.

Therefore, I hope that you have understood How to use ComboBox in UserForm in Excel VBA, maybe if you do not understand some options, then you can comment us, which we will answer soon and for more information, you can follow us on Twitter, Instagram, LinkedIn and you can also follow on YouTube.

DOWNLOAD USED EXCEL FILE FROM HERE>>

You can also see well-explained video here about How to use ComboBox in UserForm in Excel VBA

Leave a Reply