Create Excel UserForms For Data Entry
Create Excel UserForms For Data Entry
Create Excel UserForms For Data Entry
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
When working in Excel, you have a few ways to get information from a user and allow them to enter data.
These include the following:
Message boxes.
Input boxes.
The GetOpenFilename method.
The GetSaveAsFilename method.
The FileDialog method.
Excel worksheets.
UserForms.
https://powerspreadsheets.com/create-excel-userforms/ 1/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Out of the features I describe above, UserForms are one of the most powerful and e cient alternatives.
START
Unless theLEARNING EXCEL
information VBA you need
or input EXCEL ANDfrom
to get VBA the
TRAINING
user RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
is limited, UserForms are usually a good solution.
In this UserForms Tutorial, you nd all the information you need to start creating your own UserForms in
Excel. This blog post is organized as follows:
1. First section: I introduce (i) UserForms, (ii) the simple 6-step process you can use to create Excel
UserForms, and (iii) the main constructs you use when designing and programming UserForms.
2. Second section: I walk you through a step-by-step practical example of how to create a simple
UserForm for data entry. In this section, you can see how the process of creating a UserForm
(described in section #1) looks in practice.
This Tutorial is accompanied by an Excel workbook example that allows you to follow each of the steps I
describe in the second section. You can get immediate free access to this workbook by clicking the button
below.
https://powerspreadsheets.com/create-excel-userforms/ 2/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The following Table of Contents lists the main sections of this Tutorial.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
What Is A UserForm
Why Work With UserForms
How To Create An Excel UserForm: Overview
How To Insert A New UserForm
How To Add Controls To A UserForm With The Toolbox
The Toolbox
Group #1: Controls That In uence The Appearance Of Your UserForm
Group #2: Controls That Allow Users To Enter Data, Make Selections Or Issue A Command
How To Select, Move Or Resize UserForm Controls And UserForms
The UserForm Grid
The Format Menu Or UserForm Toolbar
How To Customize A UserForm Or Its Controls
UserForm Or Control Properties Vs. Other VBA Properties
The Properties Window
How To Modify Properties With The Properties Window
Why Modify The Name Property Of Your UserForms Or UserForm Controls
How To Remove Controls From A UserForm
How To Assign VBA Code To A UserForm
What Is A UserForm Code Window And Why You Work With It
How To Toggle Between The Code And UserForm Windows
Why UserForms Work With Event-Handler Procedures
How To Create Event-Handler Procedures For UserForms
How To Refer To UserForm Controls Within Your Code
How To Display Or Load A UserForm
Where To Store The Macro That Displays A UserForm
How To Display A UserForm From The VBE
How Is The Control Flow When Excel Displays A UserForm
How To Close Or Hide A UserForm
https://powerspreadsheets.com/create-excel-userforms/ 3/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
What Is A UserForm
When working with VBA, you usually use the term “UserForm” to refer to dialog boxes.
A UserForm is an object. This object represents a window or dialog box within Excel's User Interface. By
working with the UserForm object, you can easily create custom dialog boxes. Each of these dialog boxes
you create is held within an UserForm object.
You can think of a UserForm as a blank canvas. Within this canvas, you can place different elements,
known as controls. Controls are, themselves, also objects. UserForm controls are the objects users work
with to provide input through the UserForm.
You can nd a description of the main controls you can work with further below. These controls are
commonly used within Excel built-in dialog boxes. Therefore, once created, the general appearance and
behavior of the custom dialog boxes you create with UserForms is usually like that of Excel's built-in
dialogs.
https://powerspreadsheets.com/create-excel-userforms/ 4/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
As I mention at the beginning of this UserForms Tutorial, there are a few ways in which you can display
information and get input from a user. Some of the non-UserForm alternatives, such as Message and Input
Boxes, work great in relatively simple cases. In fact, in such simple cases, Message and Input Boxes are
probably more appropriate than UserForms.
There are, however, several circumstances where those alternatives aren't powerful enough for your
purposes. Consider, for example, the following scenarios or considerations:
A user should make choices or decisions that can't be adequately captured by the limited controls
available in Message or Input boxes.
The macro requires the user to make several different data entries.
The user input you require is too specialized or complex for Message or Input boxes.
You want to restrict the choices users can make or the data they can enter by establishing
sophisticated or complex data validation and controlling rules.
You want to ensure that users can easily navigate a data entry form without confusion.
More broadly, and in the words of Excel MVP Tom Urtis (in the Excel VBA 24-Hour Trainer):
“ UserForms enable you to interact with your users in ways that you can't when using standard
Message Boxes, InputBoxes, or controls embedded onto your worksheet.
https://powerspreadsheets.com/create-excel-userforms/ 5/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
This doesn't mean that UserForms and, more generally, ActiveX controls are perfect or that they should be
START
your go-toLEARNING EXCEL
choice. There VBA
are EXCEL AND
some downsides to VBA TRAINING
UserForms. RESOURCES
For VBA CODE
example, as explained GENERATOR
by Excel MVP ACADEMY LOGIN
Jordan Goldmeier in Advanced Excel Essentials, UserForms can sometimes act unpredictably. Jordan also
explains how differences in factors such as “internal settings and hardware” may result in UserForms
appearing “different across different computers”.
1. Insert a UserForm.
2. Add controls to the UserForm.
3. Move or resize the added UserForm controls, as required.
4. Customize the UserForm or its controls.
5. Assign VBA code to the UserForm.
. Display or load the UserForm.
7. Close or hide the UserForm.
1. Go to the Visual Basic Editor by, for example, using the “Alt + F11” keyboard shortcut.
2. Go to the Project Explorer, and right-click on the workbook (Project) where you want to insert the
UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 6/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 7/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 8/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 9/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 10/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Once you complete the process above, Excel the inserts the UserForm. By default, the UserForm contains
an empty dialog box. Notice that, in addition to displaying the UserForm window on the right side of the
screen, the VBE adds the following items to the Project Explorer:
A Forms node. If the VBA Project you're working on already contains a Forms node, the VBE doesn't
add it again.
A new UserForm. This UserForm appears within the Forms collection.
https://powerspreadsheets.com/create-excel-userforms/ 11/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
A UserForm object can hold a single dialog box. Therefore, you must create and insert a new UserForm for
each dialog box you want to create. However, you have signi cant exibility regarding the amount of
UserForms you can store within a single workbook.
Usually, in addition to displaying the new UserForm, the VBE shows a oating window known as the
Toolbox. The Toolbox is, also, usually displayed when you activate a UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 12/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
This Toolbox is the feature you use to add controls to the UserForm you just created. You can learn more
about it in the appropriate section below.
If your Visual Basic Editor doesn't display the Toolbox, do either of the following:
https://powerspreadsheets.com/create-excel-userforms/ 13/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 14/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 15/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Click on the UserForm, in the place where you want to add the control. This results in the created
control having its default size.
https://powerspreadsheets.com/create-excel-userforms/ 16/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Alternatively, you can click-and-drag within the UserForm. This allows you to specify the size of the
control.
3. If necessary, you can move or resize the control, using commonly-used methods. You can nd further
details about some of these methods below.
If you need to add the same control several times to a single UserForm, you can take advantage of a
shortcut by proceeding as follows:
https://powerspreadsheets.com/create-excel-userforms/ 17/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. Repeat step #2 as required until you've added the number of controls you need.
https://powerspreadsheets.com/create-excel-userforms/ 18/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
4. Click on the Select Objects command in the Toolbox to restore the mouse pointer to Selection mode.
In the example above, I work with a Label. This is only 1 of the different controls you can add to your
UserForms. To better understand the different controls you can add, let's explore…
The Toolbox
The Toolbox is a relatively simple oating window that allows you to add ActiveX controls to your
UserForms. You work with the Toolbox because the VBE's menu doesn't have commands that allow you to
add UserForm controls.
https://powerspreadsheets.com/create-excel-userforms/ 19/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Out of the 16 icons that appear in the Toolbox, 15 are controls you can insert in your UserForms. You can
divide these controls in the following groups:
The remaining control is Select Objects. As indicated by its name, Select Objects allows you to select and
manipulate the different elements of your UserForm.
You rarely need to click on the Select Objects control. This is because Select Objects is the default control
and the mouse pointer usually returns to this mode automatically. According to author Richard Mans eld (in
Mastering VBA for Microsoft O ce 2016), there are 2 common cases where you need to click on the Select
Objects control:
1. If you select a control but change your mind before using it.
https://powerspreadsheets.com/create-excel-userforms/ 20/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
2. If you add the same control several times to a single UserForm by using the technique I describe in
START LEARNINGsection
the previous EXCEL(double-clicking
VBA EXCELon
AND
theVBA TRAINING
control withinRESOURCES
the Toolbox). VBA CODE GENERATOR ACADEMY LOGIN
In both cases, you restore the mouse pointer to Selection mode by clicking on Select Objects.
Which controls you choose to add to a UserForm depend on the objective you're trying to achieve. The
following sections brie y introduce the 15 controls that are available in the Toolbox.
1. Label: Displays a text label. You commonly use labels to (i) identify a section of the UserForm, or (ii)
display information.
https://powerspreadsheets.com/create-excel-userforms/ 21/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
2. Frame: Displays a frame where you can enclose other controls. This grouping can be for either
START LEARNING
aesthetical EXCEL VBA
or logical purposes. EXCEL AND
You can, forVBA TRAINING
example, use RESOURCES VBA
Frames to (i) group CODEcontrols
several GENERATOR
that are ACADEMY LOGIN
logically related, or (ii) distinguish between different sets of OptionButton controls. Additionally,
Frames allow you to separate different groups of OptionButtons (described in Group #2 below)).
3. MultiPage: Displays a container with tabs. This is the control you usually use to create dialog boxes
with tabs.
https://powerspreadsheets.com/create-excel-userforms/ 22/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 23/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
If you choose to display an Image, consider that Images are stored within the workbook you're using.
Therefore, Images can have a substantial in uence on the size of your workbook. Usually, you want to
avoid using (i) too many Images, or (ii) Images that are too large.
https://powerspreadsheets.com/create-excel-userforms/ 24/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. ComboBox: Displays a drop-down list, where only 1 item is visible at a given time. Users can use the
drop-down list to select an item. Additionally, users can normally make entries different from those
within the list. In other words, you can think of a ComboBox as a combination of a TextBox and a
ListBox.
https://powerspreadsheets.com/create-excel-userforms/ 25/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. ListBox: Displays a list. Users can select 1 or more items from the list, depending on the setting you
specify for the ListBox.MultiSelect property.
4. CheckBox: Displays a checkbox. Allows users to specify a binary choice: True or False. If the checkbox
is checked, its value is True. If the checkbox isn't checked, its value is False.
https://powerspreadsheets.com/create-excel-userforms/ 26/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
5. OptionButton: Usually used in groups. When you have a set of OptionButtons, users can generally
select only 1. When a user selects 1 option, Excel automatically de-selects the other options. This
ensures that users only select a single option from the group.
https://powerspreadsheets.com/create-excel-userforms/ 27/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
You can use Frames (describe in Group #1 above) to separate OptionButtons. OptionButtons within a
Frame are treated as a single group, separate from other groups of OptionButtons. This allows you to
use several sets of OptionButtons, where the user can select an option in each group. Alternatively,
you can work with the OptionButton.GroupName property.
In both cases, the idea is the same: grouped OptionButtons are mutually exclusive. Therefore, a user
can select 1 option from within the group. If you don't explicitly group OptionButtons using 1 of the
methods I describe above, Excel treats all the OptionButtons in the UserForm as the same group.
. ToggleButton: Displays a toggle button. Users can use this button to toggle between 2 states: True
and False. If the ToggleButton is pressed, its value is True. If the ToggleButton isn't pressed, its value
is False. The appearance of a ToggleButton depends on the current state.
https://powerspreadsheets.com/create-excel-userforms/ 28/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
7. CommandButton: Displays a button, which users can click. When the user clicks a button, your VBA
START LEARNING
Application EXCEL
usually VBA
performs anEXCEL
action.AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
. ScrollBar: Displays a scrollbar. Users can drag the scrollbar to specify a value.
https://powerspreadsheets.com/create-excel-userforms/ 29/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
9. SpinButton: Displays a spinner. Allows users to modify a value by clicking on 1 out of 2 arrow buttons.
You can have SpinButtons with either vertical or horizontal orientation. If the spinner is vertically-
oriented, the up arrow increases the value and the down arrow decreases it. If the spinner is
horizontal, the right arrow increases and the down arrow decreases the value.
https://powerspreadsheets.com/create-excel-userforms/ 30/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
10. RefEdit: Displays a reference edit control, which is a cell range input eld. Users can use this control to
enter or select a cell or range of cells.
https://powerspreadsheets.com/create-excel-userforms/ 31/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
You're, strictly speaking, not limited to using the built-in controls within the Toolbox or Excel. This is because
you can customize the Toolbox and use other ActiveX controls. However, in this UserForms Tutorial, I
introduce only the controls that appear within the Toolbox. Those are the most commonly-used.
https://powerspreadsheets.com/create-excel-userforms/ 32/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Select several controls by either (i) pressing and holding the Ctrl key while you select controls with the
mouse, (ii) pressing and holding the Shift key while you select controls with the mouse, or (iii) clicking-
and-dragging your mouse to enclose the group of controls you want to select.
https://powerspreadsheets.com/create-excel-userforms/ 33/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Resize a control by selecting and dragging the sizing handles on the control's border.
https://powerspreadsheets.com/create-excel-userforms/ 34/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The UserForm itself also has sizing handles, which you can use to resize the UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 35/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 36/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The purpose of such grid is to help you align all the controls within the UserForm. Depending on your
settings, the controls you work with snap automatically to the grid.
The grid is, in any case, not visible in the actual UserForm displayed to the users.
You determine these settings from the General tab of the Options dialog. You can get to this tab in the
following 2 easy steps:
https://powerspreadsheets.com/create-excel-userforms/ 37/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
https://powerspreadsheets.com/create-excel-userforms/ 38/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The settings that apply to the grid are grouped under Form Grid Settings. Within this group of settings, you
nd the following:
1. Show Grid: Allows you to specify whether the grid is shown (or not shown). You can set this by
checking (or unchecking) the box to the left of “Show Grid”.
If the checkbox is selected, the grid is displayed. If the checkbox isn't selected, the grid isn't displayed.
https://powerspreadsheets.com/create-excel-userforms/ 39/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Grid Units: Allows you to set the size of the individual grid elements (the distance between the grid
dots). You do this by specifying the width and height, in points, within the Width and Height elds. The
default value is 6 points for both height and width. The larger the values, the bigger the separation
between grid dots.
https://powerspreadsheets.com/create-excel-userforms/ 40/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. Align Controls to Grid: Allows you to specify whether controls align or snap to the grid. If you want the
controls to snap to grid, select the checkbox next to the left of “Align Controls to Grid”. If the checkbox
isn't selected, controls don't align to the grid.
https://powerspreadsheets.com/create-excel-userforms/ 41/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Once you've selected the settings you want to use, click the OK button to con rm your selections.
https://powerspreadsheets.com/create-excel-userforms/ 42/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
I describe the main commands below. First, let's look at the different ways you can access them:
https://powerspreadsheets.com/create-excel-userforms/ 43/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
2. Go to the Format menu and select the command you want to apply.
https://powerspreadsheets.com/create-excel-userforms/ 44/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 45/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
1. If you can't see the UserForm toolbar, make it visible by going to View > Toolbars > UserForm.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 46/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 47/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
2. Select the command you want to apply from the context menu.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The available commands may vary slightly, depending on the context you're in and which of the 3 methods
above you use to access them.
When resizing or moving controls, the VBE must use 1 of them as a reference. You can identify which
controls are moved or resized, and which control is used as reference, based on the color of their sizing
handles. Controls that are resized or moved have black sizing handles. The control that is used as
reference has white sizing handles.
https://powerspreadsheets.com/create-excel-userforms/ 48/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The reference control is usually the last one you click on prior to executing the command. This allows you
to choose the reference control after you've selected all the controls you want to manipulate.
1. Align: Use this to align several controls. You can choose any of the following alignment options:
https://powerspreadsheets.com/create-excel-userforms/ 49/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Lefts: Aligns the selected controls to the left border of the reference control.
Rights: Aligns the selected controls to the right border of the reference control.
https://powerspreadsheets.com/create-excel-userforms/ 50/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Tops: Aligns the selected controls to the top border of the reference control.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Middles: Aligns the (vertical) center of the selected controls.
Bottoms: Aligns the selected controls to the bottom border of the reference control.
2. Make Same Size: Allows you to resize the selected controls so that they have the same dimensions.
You can choose from within the following resizing options:
https://powerspreadsheets.com/create-excel-userforms/ 51/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Width: Resizes the selected controls to be of the same width as the reference control. The
height of the controls doesn't change.
Height: Resizes the selected controls to be of the same height as the reference control. The
width of the controls isn't changed.
Both: Resizes the selected controls to have the same height and same width.
https://powerspreadsheets.com/create-excel-userforms/ 52/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
3. Size to Fit: Auto ts the selected control(s). In other words, the control(s) are resized per their
START LEARNING EXCEL VBA
contents. EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
4. Size to Grid: Resizes the selected control(s) to the nearest grid points.
https://powerspreadsheets.com/create-excel-userforms/ 53/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
5. Horizontal Spacing: You can use these settings to specify the horizontal spacing between the
selected controls. Choose from the following spacing options:
https://powerspreadsheets.com/create-excel-userforms/ 54/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Make Equal: Makes the horizontal spaces between the selected controls equal.
https://powerspreadsheets.com/create-excel-userforms/ 55/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
. Vertical Spacing: Allows you to specify the vertical spacing between the selected controls. You can
use the same options as when working with Horizontal Spacing (above).
https://powerspreadsheets.com/create-excel-userforms/ 56/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Make Equal: Makes the vertical spaces between the selected controls equal.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Increase: Increases the vertical spacing between the controls.
7. Center in Form: Allows you to center the selected control(s) horizontally or vertically within the
UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 57/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Horizontally.
Vertically.
. Arrange Buttons: You can use these settings to arrange CommandButtons either of the following
ways:
https://powerspreadsheets.com/create-excel-userforms/ 58/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Right: Arranges the selected CommandButton(s) on the right side of the UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 59/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
10. Ungroup: Ungroups controls that were previously grouped (for example, by using #9 above).
https://powerspreadsheets.com/create-excel-userforms/ 60/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
11. Order: Allows you to order a stack of controls from the front to the back. You can choose any of the
following commands:
https://powerspreadsheets.com/create-excel-userforms/ 61/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Bring to Front: Brings the selected control to the front of the stack.
Send to Back: Sends the selected control to the back of the stack.
https://powerspreadsheets.com/create-excel-userforms/ 62/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The UserForm toolbar contains several of the commands I list above. Additionally, it contains a Zoom drop-
down list. This zoom feature allows you to zoom into or out of the UserForm controls. In other words,
controls are resized per the percentage you choose.
https://powerspreadsheets.com/create-excel-userforms/ 63/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
This applies only to some properties, particularly those related to size and position such as Height,
Width, Left and Top. You can learn more about this topic by reading the previous section.
This is the option you generally use while designing your UserForm within the VBE and is the focus of
this section. The properties you set through the Properties Window are usually static (vs. dynamic)
and, therefore, you rarely use VBA code (#1 above) to modify them later.
While designing a UserForm within the VBE, you can change a property through the Properties Window in
the following 3 easy steps:
1. Within the UserForm window, select (i) the control you want to customize, or (ii) the UserForm itself.
https://powerspreadsheets.com/create-excel-userforms/ 64/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 65/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Go to the Properties Window and select the property you want to modify.
In this UserForms Tutorial, I focus on the basics of creating and designing UserForms. Therefore, I only
explain how to use the Properties Window of the VBE for these purposes. In the UserForm example that
https://powerspreadsheets.com/create-excel-userforms/ 66/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
appears in the second section of this blog post, you can nd some basic examples of how to use VBA to set
theSTART LEARNING
properties EXCEL VBA
of a UserForm EXCEL programmatically.
or its controls AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The UserForm object and the controls within the UserForm itself are also objects and, therefore, also have
properties. The basic purpose of these properties doesn't change: they allow you to describe the attributes,
characteristics or qualities of an object.
There's, however, an important difference between the way you usually work with properties (i) within VBA,
and (ii) when dealing with UserForms and UserForm controls.
When you create macros, you usually use VBA code to either return (read) or modify (write) the current
property setting. When you work with UserForms, you can also use VBA. However, you can also modify
UserForm and UserForm control properties in a different way:
By using…
https://powerspreadsheets.com/create-excel-userforms/ 67/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The Properties Window shows the properties of the currently-selected object. If your current selection
includes more than 1 object, the Properties Window lists the properties that are common to the selected
objects.
Alternatively, you can use the drop-down list at the top of the Properties Window to specify the object
whose properties you want to see.
https://powerspreadsheets.com/create-excel-userforms/ 68/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Objects have different properties, although some properties are commonly-shared by different objects.
Therefore, the appearance of the Properties Window changes depending on the object you select.
Additionally, the Properties Window can display the properties of the same object organized per 2 different
criteria. You select the organization criteria by choosing 1 of the 2 tabs the Properties Window has:
https://powerspreadsheets.com/create-excel-userforms/ 69/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Regardless of the categorization criteria you use, the properties don't change. The Properties Window lists
an object's properties and those properties don't change just because they're listed in a different order.
Therefore, once you've selected the object you want to work with, you can proceed as follows:
1. Identify the property you want to modify using the names that appear in the left column of the
Properties Window.
https://powerspreadsheets.com/create-excel-userforms/ 70/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Double-click the right column of the Properties Window and enter the new property setting.
https://powerspreadsheets.com/create-excel-userforms/ 71/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. By selecting a setting from a pre-set list of values. Properties that can take a limited list of
values have a drop-down list in the Properties Window. You can easily identify such properties
because, when you select one, the VBE displays a drop-down button.
When working with these properties you can either (i) click on the drop-down and select a value,
or (ii) double-click the property name or property value to cycle through the available values.
3. By opening a dialog box. You can identify the properties whose setting you specify through a
dialog box because, when selected, the VBE displays a button with an ellipsis (…).
https://powerspreadsheets.com/create-excel-userforms/ 72/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
You can modify the properties of several objects at the same time. To do this, select all the objects whose
property you want to modify prior to executing the 2-step process I describe above. When you select several
objects at the same time, the Properties Window displays those properties that are common to the
selection.
https://powerspreadsheets.com/create-excel-userforms/ 73/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Some of the properties of the UserForm are default settings for new controls. In other words, the new
controls you add to the UserForm are in uenced by that property setting. Therefore, if you modify those
default control settings:
Controls added after the property modi cation use the new property setting, but…
Controls added prior to the property modi cation remain unchanged and don't use the new property
setting.
Each object has its own properties. These properties generally vary from object to object. There are,
START some
however, LEARNING EXCEL that
properties VBA are common
EXCEL AND VBA TRAINING
to several differentRESOURCES VBA CODE
objects. Commonly-used GENERATOR
properties ACADEMY LOGIN
include Name, Width, Height, Left, Right, Value and Caption. In fact, UserForms and all UserForm controls
have the Name property.
In practice, you usually modify just a few properties through the Properties Window. Name is 1 such
property that you usually set through the Properties Window.
Every time you add a UserForm to a Project, the Visual Basic Editor assigns a default name:
“ UserForm#
“#” is an integer that starts at 1 and increases sequentially. Therefore, the rst UserForm you add is
UserForm1. The second is UserForm2. The third is UserForm3. And so on…
This may look familiar. Excel uses similar naming conventions for workbooks, worksheets, and regular VBA
modules (among others).
That same rule applies to the controls within a UserForm. For example, if you're working with Label controls,
the rst Label is named Label1. The second is Label 2. And so on…
You can nd the name of a UserForm or UserForm control by checking its Name property in the Properties
Window. This property is important:
You use the Name property of a UserForm or a UserForm control to refer to it when creating your VBA
code. Since you may use these names relatively often, you may prefer using names that are more
descriptive and meaningful than the default ones.
https://powerspreadsheets.com/create-excel-userforms/ 75/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Notice, additionally, that any time you change the Name property of a UserForm or a UserForm control, you
START
may haveLEARNING
to go backEXCEL VBA
to your EXCEL
VBA code AND VBA
to update TRAINING
the object RESOURCES
references. VBAyou
To avoid this, CODE
mayGENERATOR
prefer ACADEMY LOGIN
modifying the names of your UserForms and UserForm controls as soon as possible after creating them
and prior to writing your VBA code.
A common naming convention for UserForms and UserForm controls involves adding a control identi er
at the beginning of the name. You do this by adding a 3-letter pre x to the control name. The following table
lists some commonly used pre xes described in, among others, Excel 2016 Power Programming with VBA
and Mastering VBA for Microsoft O ce 2016.
https://powerspreadsheets.com/create-excel-userforms/ 76/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
CommandButton cmd
Frame fra
Image img
Label lbl
MultiPage mpg
OptionButton opt
RefEdit ref
ScrollBar scr
SpinButton spb
ToggleButton tgb
https://powerspreadsheets.com/create-excel-userforms/ 77/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
UserForm frm or uf
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. Select the control and go to Edit > Delete, or press the Delete key.
https://powerspreadsheets.com/create-excel-userforms/ 78/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Right-click on the control and select Delete from the context menu.
https://powerspreadsheets.com/create-excel-userforms/ 79/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. Go to the Code window of the UserForm by, for example, using the “F7” keyboard shortcut.
2. Enter the appropriate VBA code within this Code window.
This section focuses on the macros that you attach or assign to the UserForm. This is different from the
macros responsible for displaying the UserForm in the rst place.
In other words, when working with UserForms, you deal with (at least) 2 different types of Sub procedures:
https://powerspreadsheets.com/create-excel-userforms/ 80/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
1. A Sub procedure that displays the UserForm. You can read more about this topic in a section further
START LEARNING EXCEL VBA
below. EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. 1 or more event-handler procedures, which are attached to the UserForm. This is the topic of this
section.
Additional considerations apply to the VBA code you use to close the UserForm, even though this code is
commonly attached to the UserForm. I explain how you can close or hide a UserForm further below.
UserForms are class objects have a code module. This is like what occurs with other object classes,
such as Worksheets or Workbooks.
You use this module to store the procedures to be executed when a user works with the UserForm.
The procedures you assign to UserForms are event-handler procedures. In other words, these
procedures are executed when an event occurs. In the case of UserForms, these events are the
consequence of the user interacting with the UserForm.
The event-handler procedures which are executed when a user works with the UserForm. These
event-handler procedures are stored within the UserForm Code window.
The procedure(s) that control the display of the UserForm. These procedures are usually stored within
a regular module, and never within the UserForm Code module. You can read more about how to
display a UserForm further below.
https://powerspreadsheets.com/create-excel-userforms/ 81/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
1. The UserForm window: You use this module to manipulate and customize the UserForm and its
controls.
https://powerspreadsheets.com/create-excel-userforms/ 82/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 83/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. The Code window: You use this module to create and store the event-handler procedures associated
with the UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 84/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 85/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
You can toggle back and forth between these 2 windows with any of the 3 following features:
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. The “F7” and “Shift + F7” keyboard shortcuts:
2. The View Code and View Object commands within the View menu.
https://powerspreadsheets.com/create-excel-userforms/ 86/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
3. The context menu displayed when you right-click on the UserForm within the Project Explorer.
https://powerspreadsheets.com/create-excel-userforms/ 87/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Right-click the UserForm and select View Code to go to the Code window.
Right-click the UserForm and select View Object to go to the UserForm window.
If you want to go to the UserForm window, you can generally double-click the UserForm within the Project
Explorer.
https://powerspreadsheets.com/create-excel-userforms/ 88/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
From a broad perspective, an event is something that happens while you're working with Excel. In the case
of UserForms, these are events that occur within the UserForm itself. Once the appropriate event occurs,
your event-handler procedure is executed. This way, your VBA application can respond to the user's actions.
When working with UserForms, your code must respond to both UserForm and control events. The events
you can work with vary depending on the UserForm control. In other words, UserForm controls have
different associated events.
https://powerspreadsheets.com/create-excel-userforms/ 89/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
https://powerspreadsheets.com/create-excel-userforms/ 90/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 91/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Click on the Object drop-down list that appears at the top left side of the UserForm Code window. This
drop-down is labeled “(General)”.
https://powerspreadsheets.com/create-excel-userforms/ 92/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 93/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
When you expand this drop-down list, the VBE displays the UserForm and all the UserForm controls
within the relevant UserForm.
https://powerspreadsheets.com/create-excel-userforms/ 94/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 95/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. Select the object you want to work with.
https://powerspreadsheets.com/create-excel-userforms/ 96/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 97/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
4. Once you select an object, the VBE includes the declaration and End statements for a Sub procedure.
This Sub procedure corresponds to the default event of the object you chose.
In the screenshot below, the VBE enters the opening and closing statements for the Sub procedure
triggered by the Click event of the UserForm object (Private Sub UserForm_Click()).
https://powerspreadsheets.com/create-excel-userforms/ 98/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 99/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
5. If you want to work with the default event of the chosen object, you can start working on your Sub
procedure. Use the statements entered by the VBE in step #4 above as a basis.
. Click on the Procedure drop-down list, which appears at the top right side of the UserForm Code
window. The label of this drop-down is “(Declarations)”.
https://powerspreadsheets.com/create-excel-userforms/ 100/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 101/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The expanded drop-down list includes all the events that apply to the object you're working with.
https://powerspreadsheets.com/create-excel-userforms/ 102/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 103/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
7. Select the event you want to work with.
https://powerspreadsheets.com/create-excel-userforms/ 104/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 105/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
. Once you select an event, the VBE enters new declaration and End statements for a Sub procedure.
This Sub procedure corresponds to your chosen object and event.
https://powerspreadsheets.com/create-excel-userforms/ 106/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 107/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
9. Notice that the VBE doesn't delete the declaration and End statements for the Sub procedure that
works with the default event (step #4). If you want to keep a clean module, you can delete them.
https://powerspreadsheets.com/create-excel-userforms/ 108/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 109/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
If you're working in the UserForm window, you can use an alternative process. In this case, you can get the
START
VBE LEARNING
to enter EXCEL VBA
the declaration EXCEL
statement AND
for the VBA TRAINING
event-handler RESOURCES
procedure VBA CODE
in the following GENERATOR
2 simple steps: ACADEMY LOGIN
1. Either (i) double-click on the object you want to work with, or (ii) right-click on the object and select
“View Code”.
2. The VBE takes you to the UserForm's Code window. Additionally, the VBE enters the declaration and
End statements for the Sub procedure that handles the default event of the object, and places the
cursor between these 2 statements.
https://powerspreadsheets.com/create-excel-userforms/ 110/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
For example, in the screenshot below, the VBE adds the opening and closing statements for a macro
START LEARNING
triggered EXCEL
by the Click VBA EXCEL
event of the AND VBA TRAINING
CommandButton RESOURCES
(Private VBA CODE GENERATOR
Sub CommandButton1_Click()) ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 111/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 112/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
If you want to work with the default event of the object, you can start coding your Sub procedure.
If you want to work with another event, repeat steps #6 through #9 from the process I describe above,
as follows:
https://powerspreadsheets.com/create-excel-userforms/ 113/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 114/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Select the event you want to work with.
https://powerspreadsheets.com/create-excel-userforms/ 115/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 116/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. Start coding your Sub procedure, using the declaration and End statements that the VBE enters
as a basis.
https://powerspreadsheets.com/create-excel-userforms/ 117/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 118/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
4. If necessary, delete the declaration and End statements for the default event.
https://powerspreadsheets.com/create-excel-userforms/ 119/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
UserForms and UserForm controls are objects. You generally refer to them by using their Name property.
TheSTART
NameLEARNING EXCEL
property is the VBA EXCEL AND VBA TRAINING
rst in an alphabetically-organized RESOURCES
Properties Window. VBA CODE GENERATOR ACADEMY LOGIN
You can see how to, and why, modify the Name property of UserForm controls in a previous section.
You can see the UserForm as the parent object of the controls within it. Therefore, the basic control
reference structure is as follows:
“ UserForm.Control
“UserForm” is the UserForm object. “Control” is the control you're referring to.
However, you usually refer to controls within event-handler procedures that are stored in the UserForm's
Code module. Therefore, you can simplify the reference by omitting a reference to the UserForm. In this
case, you can refer to a control as follows:
“ Control
https://powerspreadsheets.com/create-excel-userforms/ 121/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
An additional alternative is to use the Me keyword to refer to the UserForm. In this case, the reference
START LEARNING
structure EXCEL VBA
is as follows: EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
“ Me.Control
2. Within the appropriate procedure, enter a statement that uses the Show method of the UserForm
object. The basic structure of this statement is as follows:
“ UserForm.Show
“UserForm” is an optional UserForm object. If you omit this quali er, VBA assumes you're referring to
the UserForm that is associated with the active UserForm module.
The Show method has 1 parameter: modal. This allows you to specify whether the UserForm is modal
or modeless. I don't cover this topic in this UserForms Tutorial.
When choosing the procedure in which to include the Show method, consider how and when you want the
user to access the UserForm. You can, for example:
You can load a UserForm, without displaying it, by working with the Load statement. In this case, the basic
statement syntax is as follows:
“ Load UserForm
When a UserForm is loaded, it exists in memory but isn't visible. Therefore, you can programmatically work
with the UserForm. The user, however, can't interact with it.
Once you want to display a previously-loaded UserForm, you can use the Show method of the UserForm
object.
You usually load a UserForm, without displaying it immediately, when the UserForm is complex and takes
too long to load into memory. Once the UserForm is loaded in memory, you can quickly display it.
In certain cases, VBA loads the UserForm automatically without you having to use the Load statement.
This is the case when you use the Show method of the UserForm object (above).
https://powerspreadsheets.com/create-excel-userforms/ 123/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
You use the Show method within the procedure where you want to display the UserForm. This procedure is
START
usually LEARNING
stored withinEXCEL VBAVBA module.
a regular EXCEL AND VBA TRAINING
You don't store the RESOURCES VBA
macro that displays CODE
the GENERATOR
UserForm in the ACADEMY LOGIN
UserForm Code window itself.
To understand why this is the case, it may help if you consider the following 3 separate steps:
The code that determines what happens depending on how the user interacts with the UserForm (step #3)
is stored within the UserForm. If the UserForm is never displayed, the user doesn't interact with the
UserForm and this code is never executed.
Since the code within the UserForm is never executed if the UserForm isn't displayed, you can't store the
code that determines when the UserForm is displayed in the UserForm Code module. If you store the code
that displays a UserForm within the UserForm itself, the UserForm is never displayed.
https://powerspreadsheets.com/create-excel-userforms/ 124/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
When you execute the Run Sub/UserForm command, the Initialize event of the UserForm occurs. This
option is useful for testing or preparing a UserForm you're working on.
https://powerspreadsheets.com/create-excel-userforms/ 125/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
As an alternative to the Run Sub/UserForm command, you can use the Show method of the UserForm
START
object in aLEARNING EXCEL
statement typedVBA EXCEL AND
in the Immediate VBA TRAINING
Window. RESOURCES
The basic VBA
structure of such CODE GENERATOR
a statement is: ACADEMY LOGIN
“ UserForm.Show
https://powerspreadsheets.com/create-excel-userforms/ 126/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 127/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
How Is The Control Flow When Excel Displays A UserForm
At a basic level, once the Show method of the UserForm object is called, Excel goes through the following
6-step process:
3. The interaction of the user with the UserForm usually triggers an event associated to 1 of the controls
within the UserForm. Therefore, the applicable event-handler procedure is executed.
. Once the UserForm is closed, Excel continues execution of the procedure that contains the Show
method of the UserForm object. This is the Sub procedure responsible for displaying the UserForm
(step #1 above).
In practice, however, the VBA statement that displays the UserForm is at (or near) the end of a
procedure. This is because you usually store the code that is executed after the user works with the
UserForm in the UserForm Code module. The code within the UserForm Code module is executed in
earlier steps of this process (steps #2 to #4 above).
You can read more about the UserForm Code module in a previous section of this UserForm Tutorial.
https://powerspreadsheets.com/create-excel-userforms/ 128/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The rst way in which a UserForm can be closed is by clicking on its Close button on the top right corner.
This generally applies to all UserForms, regardless of the VBA code you use.
You can, however, monitor whether a user clicks on the Close button by using events. Clicking on the Close
button triggers the following 2 events:
Usually, when you're creating a UserForm, you create an event-handler procedure that is triggered by the
Click event of a CommandButton. This event-handler procedure normally includes 1 of the following VBA
https://powerspreadsheets.com/create-excel-userforms/ 129/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
constructs:
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. The Unload statement, which unloads the UserForm from memory. The basic statement structure for
the Unload statement is as follows:
“ Unload UserForm
2. The UserForm.Hide method, which makes the UserForm invisible. The basic statement syntax for the
UserForm.Hide method is as follows:
“ UserForm.Hide
In both cases, if the procedure containing this statement is stored within the UserForm Code module, you
can use the Me keyword. In such a case, you can always use the same statement regardless of the Name
property of the UserForm. Additionally, you can replace the statements above with the following:
“ Unload Me
Me.Hide
https://powerspreadsheets.com/create-excel-userforms/ 130/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
You generally use the Unload statement only after all the UserForm instructions and statements have
START
been LEARNING
carried EXCEL
out. This VBA retrieving
includes EXCEL
theAND VBA
input TRAINING
data from theRESOURCES VBA CODE
UserForm and carrying out GENERATOR
any necessary ACADEMY LOGIN
actions. If you fail to do this, the UserForm has no real effect, other than displaying the UserForm itself.
I don't cover the topic of retrieving input from a UserForm in detail within this blog post. But you can see
some code examples further below.
This topic is important because, once a UserForm is unloaded, the changes made to the UserForm's
controls and their properties are reset. This results, as explained in Excel 2016 Power Programming with
VBA, your code not being “able to access the user's choices after the UserForm is unloaded.”
There may be cases where you need to use the input from a UserForm after the UserForm is unloaded.
You can usually store that data using a public-scope variable. Other possible solutions suggested by VBA
experts Dick Kusleika and Mike Alexander in Excel 2016 Power Programming with VBA include writing the
value to a worksheet cell or the Windows registry.
The UserForm.Hide method doesn't unload the UserForm from memory. It simply hides the UserForm.
Therefore, you can still access and work with the user's choices and the UserForm controls.
In fact, if you use the UserForm.Hide method on an unloaded UserForm, VBA loads the UserForm and
keeps it hidden.
“ The method you choose depends on why you don't want the UserForm to be seen. Most of the
time, you'll want the form cleared from memory, but sometimes, information that was entered
https://powerspreadsheets.com/create-excel-userforms/ 131/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
into the form needs to be referred to the next time you show the form while the workbook has
START LEARNING
remained open.EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The purpose of the example UserForm is to serve as a data entry mechanism for a workbook table
recording certain sales data. The entries are as follows:
Item.
https://powerspreadsheets.com/create-excel-userforms/ 132/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Units Sold.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The worksheet where these entries are recorded has 2 single columns. These columns match with the
entries above.
These entries are the part of the basis for several tables that I use in other Tutorials, such as this one about
Pivot Tables or this one about Power Query.
The example UserForm that you create below works with the following UserForm controls:
1 Label.
1 TextBox.
1 SpinButton.
1 Frame.
5 OptionButtons.
2 CommandButtons.
https://powerspreadsheets.com/create-excel-userforms/ 133/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
In the following sections, you follow the 6-step process described at the beginning of this Tutorial to create
START LEARNING EXCEL VBA
a UserForm: EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. Insert a UserForm.
2. Add controls to the UserForm.
3. Move or resize the UserForm controls.
4. Customize the UserForm or its controls.
5. Assign VBA code to the UserForm.
. Display or load the UserForm.
7. Close or hide the UserForm.
The purpose of this section is to show you, step-by-step, the practical process you can follow to create a
UserForm. The logic and theory behind each of these steps is thoroughly described in the appropriate
section above. Please refer to those sections for more information and details.
The UserForm example you create is very simple. My purpose with this blog post is to get you started
creating UserForms. Therefore, I don't dive into certain features or VBA constructs that you can use and add
to improve the UserForm and make it more sophisticated or complex.
2. Go to the Project Explorer and right-click on the Project (workbook) you're working on. In this example,
select “VBAProject(Create Excel UserForms For Data Entry In 6 Easy Steps.xlsm)”.
https://powerspreadsheets.com/create-excel-userforms/ 134/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
https://powerspreadsheets.com/create-excel-userforms/ 135/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 136/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Step #2: Add Controls To The UserForm
The purpose of the example UserForm example is to serve for data entry. There are only 2 required entries:
1. Item.
2. Units Sold.
Add the SpinButton, TextBox, Label and Frame controls following the same 2-step process:
In the case of the CommandButtons and OptionButtons, use the following 3-step process:
https://powerspreadsheets.com/create-excel-userforms/ 137/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
3. Click on the Select Objects command in the Toolbox to restore the mouse pointer to Selection mode.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Due to the amount of controls you include in the UserForm, start by resizing the UserForm itself. Your
purpose is to make the UserForm taller. You do this by clicking and dragging on the UserForm's lower center
sizing handle.
Once the UserForm is big enough to t all the controls you want to add, and due to the layout choice, add
the controls in the following order:
1. Frame.
2. OptionButtons.
3. Label.
4. TextBox.
5. SpinButton.
. CommandButtons.
https://powerspreadsheets.com/create-excel-userforms/ 138/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
In this step, don't worry too much in getting the precise location right. You organize the controls with more
detail in the next step.
https://powerspreadsheets.com/create-excel-userforms/ 139/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
https://powerspreadsheets.com/create-excel-userforms/ 140/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The only exceptions are the TextBox and SpinButton. The TextBox and SpinButton objects don't have a
STARTproperty.
Caption LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
In addition to the above, make the following speci c property modi cations:
1. Set the Default property of the Record Entry button to True. The Default property allows you to specify
whether a CommandButton is the default button in the UserForm.
2. Set the Cancel property of the Close Form button to True. You can use the Cancel property to specify
that a CommandButton is the Cancel button. If you do this, the user can use the Escape key as a
shortcut for the Close Form button.
3. Set the Enabled property of the TextBox to False. You can use the Enabled property to indicate
whether the TextBox is enabled and respond to the user's actions (True) or disabled (False).
4. Set the Locked property of the TextBox to True. The Locked property allows you to specify if the
user can edit the entry or data within the TextBox. By locking the TextBox, you ensure that the user
can't edit, add or delete data in the TextBox.
Follow the same 3-step process for all objects whose properties are modi ed:
The following table shows the new Name and Caption properties for each of the objects. I use “n.a.” to
indicate the cases where a property isn't a member of the object.
https://powerspreadsheets.com/create-excel-userforms/ 142/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Strictly speaking, you don't need to specify the Name property of all the objects above. This is because you
don't refer to most of them (for example, the Label and Frame) within the VBA code you create in the
following steps. However, as I explain above, you generally want to use meaningful and descriptive names
for the objects you refer to within the code.
https://powerspreadsheets.com/create-excel-userforms/ 143/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The following GIF shows the whole process to change the properties above:
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Therefore, the Sub procedure examples below are very simple. You can use more sophisticated macros and
nd several Tutorials that focus on VBA code in the Archives.
1. A macro that prepares the UserForm for use by setting the default states of the TextBox, SpinButton
and OptionButtons in the UserForm.
2. A macro that records entries.
3. A macro that connects the TextBox to the SpinButton, so that changes to the SpinButton are re ected
in the TextBox.
https://powerspreadsheets.com/create-excel-userforms/ 144/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
I explain the VBA code used to display and close the UserForm in the following steps (#6 and #7).
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The 8-step process you can follow to enter the VBA code for the UserForm is as follows:
Enters the declaration and End statements for a Sub procedure triggered by the Click event of
the CommandButton object (Private Sub commandButtonRecordEntry_Click()). The Click event
occurs when the user clicks on the CommandButton.
https://powerspreadsheets.com/create-excel-userforms/ 145/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
2. Enter the VBA code for the Sub procedure triggered when the user clicks on the Record Entry
CommandButton. This is the main Sub procedure and carries out most of the work you require.
3. Click on the Object drop-down list at the top left side of the UserForm Code window, and select the
SpinButton control (spinButtonUnits).
https://powerspreadsheets.com/create-excel-userforms/ 146/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 147/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The VBE enters the declaration and End statements for a Sub procedure triggered by the Change
event of the spinButtonUnits object (Private Sub spinButtonUnits_Change()). The Change event
occurs when the Value property of the SpinButton changes. The Value property, in turn, changes when
the user clicks any of the arrows of the SpinButton.
4. Enter the VBA code for the Sub procedure triggered when the user clicks on the arrows of
spinButtonUnits.
5. Click on the Object drop-down list, and select the UserForm object (UserForm).
https://powerspreadsheets.com/create-excel-userforms/ 148/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 149/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Because of this, the VBE enters the declaration and End statements for a Sub procedure triggered by
the Click event of the UserForm.
. Click on the Procedure drop-down list at the top right side of the UserForm Code Window, and select
the Initialize event.
https://powerspreadsheets.com/create-excel-userforms/ 150/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 151/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The VBE enters the opening and closing statements of a Sub procedure triggered by the Initialize
event of the UserForm (Private Sub UserForm_Initialize()). The Initialize event happens when the
UserForm is loaded, but prior to it being displayed. Therefore, you usually rely on Initialize to specify
default values or ll controls with data.
7. Delete the opening and closing statements entered by the VBE in step #5 above (Private Sub
UserForm_Click()).
https://powerspreadsheets.com/create-excel-userforms/ 152/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
. Enter the VBE code for the macro triggered when the UserForm is initialized.
Let's look at the VBA code for the 3 procedures you create in this step:
https://powerspreadsheets.com/create-excel-userforms/ 153/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
This macro sets the default values and selections for several controls within the UserForm, as follows:
Value of TextBox: 0.
Value of SpinButton: 0.
Selected OptionButton: Surface Studio.
You can also manipulate these properties through the Properties Window (step #4 above).
One of the main reasons I prefer to set these default property values through VBA code is that this allows
me to reuse the code within this Sub procedure to reset the UserForm and prepare it for a new entry. In fact,
the last statement in Sub procedure #2 below calls the UserForm_Initialize macro for these purposes.
https://powerspreadsheets.com/create-excel-userforms/ 154/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The statements within the block (lines #2 to #4) work with the object speci ed in the opening line of the
block (Me). You use the Me keyword to refer to the UserForm itself.
You achieve this by setting the Text property of the TextBox (.textBoxUnits.Text) to 0.
You do this by setting the Value property of the SpinButton to 0. The Value property of a SpinButton is an
integer.
You achieve this by setting the Value property of the rst OptionButton (Surface Studio) to True. The Value
property allows you to specify whether the OptionButton is selected (True).
https://powerspreadsheets.com/create-excel-userforms/ 155/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
https://powerspreadsheets.com/create-excel-userforms/ 156/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 157/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
This Sub procedure goes through the following process:
1. Find the rst empty row in the worksheet where the entered data is recorded.
2. Record the user entries in that rst empty row, as follows:
1. The Item chosen with the OptionButtons of the UserForm is recorded in column A.
2. The number of units displayed in the TextBox of the UserForm is recorded in column B.
3. Prepare the UserForm for a new entry by:
1. Resetting the values of the TextBox and SpinButton.
2. Selecting the default OptionButton (for Surface Studio).
The macro doesn't carry any data validation checks, nor handles any possible errors. For example, it doesn't
check whether the user has entered the number of units using the SpinButton. In this example, those
checks are mostly handled by the SpinButton and the properties of the TextBox you modify in step #4
above, as follows:
The user can't enter data directly in the TextBox. This is a consequence of the values you set for the
Enabled (False) and Locked (True) properties of the TextBox in step #4 above.
The number of units displayed on the TextBox is dependent on the SpinButton. In other words, the
user speci es the number of units through the SpinButton. The TextBox simply displays the current
number of units.
You achieve this through an event-handler procedure triggered by the Change event of the SpinButton
object. You can nd an example of such code below (Sub procedure #3).
This Sub procedure doesn't close the UserForm. Therefore, the user can make several entries at any time
without having to continually open the dialog box. The user can, however, close the dialog box at any time
https://powerspreadsheets.com/create-excel-userforms/ 158/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
by clicking on the Close or Close Form buttons. See step #7 below to see how to close the dialog box with
theSTART
Close LEARNING EXCEL VBA
Form button. EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Let's go through each line of code to understand how the macro works:
1. myWorksheet: An object variable. Represents the worksheet where the data is recorded.
2. myFirstBlankRow: A variable of the Long data type. Represents the number of the rst blank row in
the table where the data is recorded.
The process followed to nd the rst empty row in the worksheet is as follows:
https://powerspreadsheets.com/create-excel-userforms/ 159/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
1. The number of the last cell with data in the worksheet is found (.Cells.Find(What:=”*”,
START LEARNING EXCELLookAt:=xlPart,
LookIn:=xlFormulas, VBA EXCEL AND VBA TRAINING RESOURCES
SearchOrder:=xlByRows, VBA CODE GENERATOR
SearchDirection:=xlPrevious).Row). ACADEMY LOGIN
2. A value of 1 is added. This addition returns the number of the row below the last cell with data or, in
other words, the rst empty row in the worksheet.
Let's analyze the portion of the statement that nds the last row in the worksheet. I explain several different
ways to nd the last row in a worksheet in this VBA Tutorial.
1. The Worksheet.Cells property (.Cells) returns all the cells within myWorksheet.
2. The Range.Find method (Cells.Find) is used to search for the last cell with data within myWorksheet.
The parameters of the Range.Find method, which are within parentheses, are set as follows:
1. What: “*”. The data you're searching for. The asterisk (*) acts as wildcard. Therefore, the Find
method searches for any character sequence.
2. LookIn: xlFormulas. The type of data you're searching in. xlFormulas results in VBA searching
(looking) in the cell formulas.
3. LookAt: xlPart. Speci es whether the Find method matches the cell contents in their entirety, or
just a part of them. xlPart results in Excel doing a partial match.
4. SearchOrder: xlByRows. Speci es whether the search is carried out by rows or by columns.
Since you're looking for the last row, you set this to xlByRows.
5. SearchDirection: xlPrevious. The direction (next or previous) in which the search is carried. In
this case, you set the argument so that Excel searches for the previous (xlPrevious) match.
Once the last row in the worksheet is identi ed, 1 is added (+ 1). The resulting value is assigned to the
myFirstBlankRow variable (myFirstBlankRow =).
Executes one of the groups of statements within this block of code (lines #8 to #17) based on the value
taken by an expression. The group of statements that's executed is determined by nding which expression
matches the test expression.
The test expression is set in the opening line of code (#7) of the block. In this case, a Boolean value: True
(Select Case True).
https://powerspreadsheets.com/create-excel-userforms/ 161/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
The following table shows the tested expressions along with the statement that's executed when that
expression returns True:
https://powerspreadsheets.com/create-excel-userforms/ 162/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Overall, the consequence of the above structure is that the data recorded in the Excel worksheet depends
on the OptionButton the user chooses, as follows:
Records the number of units within the No. of units sold TextBox in the appropriate worksheet cell.
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Let's see how this works:
1. The statements sets the Value property of a cell (.Cells(myFirstBlankRow, 2).Value =) to be equal to
the Value property of the UserForm TextBox (Me.textBoxUnits.Value). The Value property of the
TextBox is determined by the SpinButton. This part of the process is controlled by the Sub procedure
#3 I explain below.
2. The rst part of the statement (.Cells(myFirstBlankRow, 2)) works as follows:
1. The Cells property (.Cells) works with the object speci ed in the opening statement of the With…
End With block (line #4). That object is represented by myWorksheet.
2. The Cells property returns a single cell. This cell is located on the rst empty row
(myFirstBlankRow) and the second column (2 or B) of the worksheet. That's the cell where the
next data entry for Units Sold is recorded.
https://powerspreadsheets.com/create-excel-userforms/ 164/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
Calls the UserForm_Initialize Sub procedure. I explain this event-handler procedure in more detail above
START
(Sub LEARNING
procedure #1). EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
The UserForm_Initialize macro sets the default values and controls of certain UserForm controls, as
follows:
TextBox: 0.
SpinButton: 0.
OptionButton selection: Surface Studio.
In other words, by calling the UserForm_Initialize Sub procedure, you reset the values and selections within
the UserForm to their defaults. This ensures that the UserForm is ready for a new entry.
https://powerspreadsheets.com/create-excel-userforms/ 165/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
This statement sets the Value property of the TextBox object (textBoxUnits.Value) to be equal to the Value
property of the SpinButton object (Me.spinButtonUnits.Value). In other words, it:
For this example, get Excel to display the UserForm in the following 3 simple steps:
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. Go to a module different from the UserForm's code module.
2. Create a Sub procedure that calls the Show method of the UserForm object.
3. Assign a keyboard shortcut to the displayUserForm macro.
If necessary, insert a new module by, for example, right-clicking on the workbook within the Project Explorer
and going to Insert > Module.
https://powerspreadsheets.com/create-excel-userforms/ 167/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Step #2: Create A Sub Procedure That Calls The Show Method Of The UserForm
Object
Create the following macro (displayUserForm):
https://powerspreadsheets.com/create-excel-userforms/ 168/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
“ userFormSalesEntry.Show
When executed, this macro displays the userFormSalesEntry you created in the previous 5 steps.
1. Open the Macro dialog box by, for example, using the “Alt + F8” keyboard shortcut.
2. Within the Macro dialog box, select the appropriate macro (displayUserForm) and click the Options
button.
https://powerspreadsheets.com/create-excel-userforms/ 169/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. Within the Macro Options dialog box displayed by Excel, assign a keyboard shortcut and click the OK
button.
https://powerspreadsheets.com/create-excel-userforms/ 170/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 171/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
1. Go to the VBE by, for example, using the “Alt + F11” keyboard shortcut.
https://powerspreadsheets.com/create-excel-userforms/ 172/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
3. Double-click on the button you want to use to close the UserForm (Close Form).
https://powerspreadsheets.com/create-excel-userforms/ 173/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Enters the declaration and End statements for a Sub procedure triggered by the Click event of
the commandButtonCloseForm object (Private Sub commandButtonCloseForm_Click()).
https://powerspreadsheets.com/create-excel-userforms/ 174/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
https://powerspreadsheets.com/create-excel-userforms/ 175/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
4. Enter the VBA code for the Sub procedure triggered when the user clicks the Close Form button. In
this example, this procedure includes a statement with the Unload statement.
The following is the code within the Sub procedure executed when the user clicks the Close Form button:
“ Unload Me
The Unload statement unloads the UserForm from memory. This results in the dialog box being dismissed.
https://powerspreadsheets.com/create-excel-userforms/ 176/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
3. To make an entry:
https://powerspreadsheets.com/create-excel-userforms/ 177/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
4. Repeat step #3 as many times as required, depending on the number of entries you want to make.
Every time I click the Record Entry button, the entry is recorded in the table.
When I click the Close Form button, the dialog box is closed.
https://powerspreadsheets.com/create-excel-userforms/ 178/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
START LEARNING EXCEL VBA EXCEL AND VBA TRAINING RESOURCES VBA CODE GENERATOR ACADEMY LOGIN
Conclusion
After reading this UserForms Tutorial, you have the knowledge and resources to start creating UserForms
in Excel now. The following are some of the topics you learned about:
https://powerspreadsheets.com/create-excel-userforms/ 179/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
How to create the macros that power your UserForms. This includes the VBA code you use to both: (i)
START LEARNING
display, EXCEL
load, close VBA
and EXCEL AND
hide UserForms, andVBA
(ii) TRAINING RESOURCES
respond to VBA
the user's actions CODE
within theGENERATOR
UserForm. ACADEMY LOGIN
In the second section of this UserForms Tutorial, you saw a practical example. In this example, you
followed the easy 6-step process to create a simple UserForm for data entry. Remember that this blog
post is accompanied by an Excel workbook example containing this UserForm example. You can get
immediate free access to this workbook by clicking the button below.
In practice, you're likely to work with more complex UserForms that (i) gather more data, (ii) use additional
controls, and (iii) work with more complex VBA code. In most cases, the basic principles and constructs
you've learned about by reading this UserForms Tutorial continue to apply.
https://powerspreadsheets.com/create-excel-userforms/ 180/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
3. Excel Resources
Copyright © 2015–2021 PDS Intelligence Pte. Ltd. All rights reserved. | Imprint/Impressum | Privacy Policy | A liate Disclosure | Terms and Conditions |
Limit of Liability and Disclaimer of Warranty | Excel ® is a registered trademark of the Microsoft Corporation. Power Spreadsheets is not a liated with
https://powerspreadsheets.com/create-excel-userforms/ 181/182
5/20/2021 Create Excel UserForms For Data Entry In 6 Easy Steps: Tutorial And Practical Example
https://powerspreadsheets.com/create-excel-userforms/ 182/182