UserForm is a customized interface and acts as a VBA container and can add various controls as per the required functionality, each of which has certain usage and related properties. You can create your own dialog boxes with this feature. Your project can have n number of userforms wherein each userform has its own dialog own.

Creating a Userform

There are two ways to install a UserForm in VBA, which are as follows. 

Process 1: Right Click on VBAProject ->Click on insert -> Click on Userform.

VBA Creating, Displaying, Uploading UserForms

Process 2: Click on Insert from the ribbon bar-> Click on Userform.

VBA Creating, Displaying, Uploading UserForms

In both the process, you will notice a folder has been introduced with name Forms (inside which it consists the UserForm) in the VBA Project. Further clicking on the UserForm will straightway lead you to a window entitled UserForm1 (though the name can be changed from the properties) following with a “controls” toolbox.

VBA Creating, Displaying, Uploading UserForms

Adding control to Userform

Controls are added to a UserForm to accept the inputs from the user and make it more user-friendly. The control box can be resized by stretching the adjustment handles and can be dragged to any position. You can even adjust the spacing and the alignment of the UserForm. There are two ways to add the controls to your useform:

  • Select the required control and drag it to the Userform. 
  • The Second method is to left-click on the control available in the ToolBox, in the form left-click, and the control will be automatically added.

Example: Create a VBA userform, which takes the basic information from the user and update it on the excel sheet. Refer to the below image to get a glimpse of the form.

VBA Creating, Displaying, Uploading UserForms

Output

Case 1: Fill all the details and press the save button. The excel sheet will be update with the inserted values. Repeat it two three times and you notice the names are present in the sorted order.

VBA Creating, Displaying, Uploading UserForms
VBA Creating, Displaying, Uploading UserForms

Case 2: Keep any field unfilled, and you will notice and message error pops out notifying that blank field can’t be entertained.

VBA Creating, Displaying, Uploading UserForms

Pin It on Pinterest

Share This