Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: User Forms

User Forms are one of the very important features in Excel Macro. It provides and an interface to the user for interaction with the workbook. It has many controls which makes user’s life easy for entering the data from excel in a specific manner or reading the particular data from the excel.

Getting Started : Create a Blank User Form

  1. To open or create a new user form, follow the steps below
  2. Open an Excel file
  3. Press “Alt+F11” to open the Microsoft Visual Basic Editor.
  4. Make Project Explorer and Property Window visible from “view menu” (If not already visible)
  5. Select the Project from the Project Explorer.
  6. Form “Insert” menu, select “User Form
  7. User Form - Create User Form

    User Form – Create User Form

  8. You will see “UserForm1” under “Form” section
  9. One the right side you will see a Userform .
  10. User Form - Insert New Form

    User Form – Insert New Form

  11. Make All Controls (Tool box) visible from “View menu” if already not displayed.
  12. User Form - Tool Box

    User Form – Tool Box

  13. Look for all the Properties of the User Form in Property Window.
  14. User Form - Property Window

    User Form – Property Window

  15. Give a Proper Name and Captionto the UserForm1,
    1. Select the Userform1
    2. Go to the Property Window,
    3. Change the Name Property to “FirstForm
    4. Change the Caption Property to “My First User Form
    5. User Form - Name and Caption

      User Form – Name and Caption

16.  Add Controls  to the User form

  • Select the control from the Tool Box and place it in the User Form.( here Command Button is selected)
  • Select or Single Click on the Command Button from the Tool Box.
  • Now Click on the UserForm, a new CommandButton will be created.
  • User Form - Add Command Button

    User Form – Add Command Button

  • Change the Button Name and Caption name in the Property Window
  • User Form - Command Button

    User Form – Command Button

  • Double Click on the button to view the Click function of the Button(Actually when you double click it first time, then only “Click” function will be created.)
  • Inside the function write Msgbox “Yeaaaahhhhh , I got Clicked”.Private Sub

          Private Sub FirstButton_Click()
                 MsgBox “Yeaaaahhhhh , I got Clicked”
          End Sub

User Form - Command Button click

User Form – Command Button click

NOTE : To Navigate Between “Code Window” and “UserForm Design Window” KeyBorad Shortcut is [Control]+[Tab]
17. Now your User Form is ready to run. All you have to do is assign this User  Form to a macro.

Macro to Open the UserForm

  1. Select the VBA Project from Project Explorer
  2. Form “Insert” menu, select “Module
  3. User Form - Insert Module

    User Form – Insert Module

  4. A new Module will be create in the Project Explorer under Modules folder
  5. Click on the Module 1, Code window will be displayed on right side.
  6. Create a Sub-Routine say with name “Sub Sumit”
  7. Display the UserForm inside the Sub-Routine using Show() function.  
  8.      Sub Sumit()
        End Sub
  9. User Form- Sub Routine

    User Form- Sub Routine

  10. Create a button in Excel WorkSheet and assign the Sub-Routine to it ( Click Here)
  11. Click on the Button on Excel
  12. UserForm ( FirstForm) will be displayed.
  13. User Form - Display

    User Form – Display

  14. Click on the CommandButton(“Click Me”)
User Form - Display - Clicked

User Form – Display – Clicked


You may also like...

Leave a Reply

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

%d bloggers like this: