Search Contextures Sites ![]()
Create an Excel UserForm
To make it easier for users to enter data in a workbook, you can create an Excel UserForm.
In this example, a parts inventory is stored on a hidden worksheet. Users enter data by opening the Excel UserForm, filling in the boxes, and clicking a button.
To view the steps in a short video, click here (video is in 3 parts).
Set up the worksheet
In this example, a parts inventory is stored on a hidden worksheet.
![]()
- Open a new workbook
- Double-click on the sheet tab for Sheet1
- Type: PartsData
- Press the Enter key
- In cells A1:D1, enter the headings for the parts inventory database, as shown at right.
- Choose File | Save, and save the workbook. In this example, the file has been named PartsLocDB.xls.
A B C D 1 PartID Location DateQty 2 12345 Store 001 3/3/2004 87 3
Add a Label to the Excel UserForm
To help users enter data, you can add label controls to describe the textboxes, or to display instructions.
- In the Toolbox, click on the Label button.
- On the UserForm, click to the left of the textbox, to add a standard sized label.
- With the new label selected, double-click on the Caption property in the Properties window.
- Type: Part
and press the Enter key- If necessary, you can resize the label, so it doesn't cover the textbox -- point to the handle on its right border, and drag to the left.
- Click on an empty part of the UserForm, to select the UserForm and to display the Toolbox.
![]()
To view the steps in a short video, click here
(video is in 3 parts).
Add Buttons to the Excel UserForm
To allow users to perform an action, you can add command buttons to the user form. This form has a button to add data to the database, and a button to close the form.
- In the Toolbox, click on the CommandButton button.
- On the UserForm, click at the bottom left, to add a standard sized CommandButton.
- With the new CommandButton selected, double-click on the Name property in the Properties window.
- Type: cmdAdd
and press the Enter key- With the new CommandButton selected, double-click on the Caption property in the Properties window.
- Type: Add this part
and press the Enter key- Click on an empty part of the Excel UserForm, to select the UserForm and to display the Toolbox.
- Repeat the above steps to add a CommandButton named cmdClose, with a label Close
- If required, you can reposition the buttons by dragging them to a new location on the UserForm.
![]()
To view the steps in a short video, click here
(video is in 3 parts).
Add code to the cmdClose button
- Select the cmdClose button
- On the Menu bar, choose View | Code.
- Where the cursor is flashing, enter the following code:
Private Sub cmdClose_Click() Unload Me End Sub
- On the Menu bar, choose View | Object, to return to the UserForm.
To allow users to close the form by pressing the Esc key:
View the steps in a
short Excel UserForm video
(video is in 3 parts).
Finish the Workbook
To finish the workbook, you can hide the sheet that contains the database.
- Switch to Excel, and activate the PartLocDB.xls workbook
- Select the PartsData sheet.
- From the menu bar, choose Format | Sheet | Hide
- Delete all other sheets, except Parts Data Entry
- Click the Click here to add Part Information button, and enter your data into the database.
- Close and save the workbook
Download the sample Excel UserForm file
Download the sample file with an enhanced Excel UserForm, with comboboxesTo view the steps in a short Excel UserForm video, click here (video is in 3 parts).
Last updated: December 21, 2009 1:05 AM
Contextures Inc., Copyright © 2009.
All rights reserved.