How to Call Userform Initialize in VBA
In this article, we will introduce user form in VBA. We will also explore an example to learn how to initialize a form in VBA functions.
Call Userform Initialize in VBA
While working with excel, we always have wondered how we can make a form with the help of which we can easily allow users to make a user data entry more controllable and easier to use.
We will go through an example in which we will create a simple form in VBA by following the steps.
-
Go to the
Developers
tab and click onVisual Basic
, as shown in the picture below. -
Click on
Insert Userform
, then click onUserform
, as shown in the picture below. -
It will create a new form, We can easily add labels and input fields by clicking on the buttons, and we will create a sample design as shown below.
The design of the form is shown below.
Now, let’s create a sub-function and try to call this user form in it. But, first, we will rename the name
property of the user form we just created in VBA to something we can remember to call, like testForm
, as shown below.
Then, we will create a new sub-function, as shown below.
#VBA
Sub showForm()
end sub
Next, we will define a new form using the name
of the form and use the property of show
to display it, as shown below.
#VBA
Sub showForm()
Dim userForm As New testForm
userForm.show
end sub
Now, we will run the code as shown below.
The above example displays the form without any when we execute the functions. This way, we can show multiple or single forms to add values to the sheet.