UserForm – ComboBox in Excel VBA

How do you insert the ComboBox combo box into the UserForm form?

The combo box is already known to us. We got to know them while creating the application for entering data . Due to the fact that the field inserted in the UserForm form is programmed in a different place, we will create an example in which we will show how to program it. Select the ComboBox control from the ToolBox and put it to the right of the TextBox1 and TextBox3 fields in the first two tabs of our application. Our fields shouldto be called ComboBox1 and ComboBox2.


How do I program the ComboBox Combo Box list?

The next step is to program the list that will be displayed after clicking on the field. Unlike ActiveX controls inserted into the data sheet, the ComboBox field in the UserForm form is programmed directly in the UserForm form code. We go successively in the project window to the View Code view of the UserForm form. The most important thing is to set the UserForm object and the Initialize trigger in the Code window . As a result, the values ​​to the ComboBox field will load when the form is launched.

The code in the Initialize trigger is programmed in the same way as in the case of regular ActiveX controls. We set the values ​​right away for both combo boxes. The example below:

Next, we should program the CommandButton buttons in the first two tabs of our program. Double click on the button in the “Netto gross” tab. The CommandButton1 button is programmed in the following way using the TextBox1, TextBox2 and ComboBox1 fields:

In the above code, we have programmed the TextBox2 field after choosing the VAT rate. The analogous operation is performed for the CommandButton2 button in the “Gross on net” tab. All of our code in the UserForm object looks like this:

At the end of the “About the program” tab, you can enter any text using, for example, the Label label . Place the label content in the frame by selecting Frame earlier.


Below I attach a file with our program:

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: