Microsoft Office Tutorials and References
In Depth Information
Displaying, loading, and hiding UserForms
Click on the body of the UserForm and then, in the Toolbox , click the
CommandButton button. Draw a command button below the Signature Waived
option button and then, with the command button still selected, in the Caption box,
enter Submit and press Enter .
Right-click the Submit command button and click View Code to display the button’s
On_Click event handling routine. Edit the Private Sub ComandButton1_Click()
subroutine so it reads as follows.
Private Sub CommandButton1_Click()
Dim lngFirstRow As Long
lngFirstRow = Worksheets(“Records”).Range(“A1048576”).End(xlUp).Row + 1
Cells(lngFirstRow, 1) = TextBox1.Value
Cells(lngFirstRow, 2) = TextBox2.Value
Cells(lngFirstRow, 3) = ListBox1.Value
Cells(lngFirstRow, 4) = OptionButton1.Value
Cells(lngFirstRow, 5) = OptionButton2.Value
In the Project pane, click UserForm1 to display it and then press F5 to run the
Use the Pounds spin button to enter 4 in the Pounds text box; use the Ounces spin
button to enter 8 in the Ounces text box; select 3Day in the list box; and then select
the Signature Waived option button. Click the Submit command button. When you
do, the UserForm writes your data to the first empty row in the Records worksheet.
Click the UserForm’s Close button to close it and then press Alt+F11 to display the
workbook. If necessary, click the Records sheet tab to display the worksheet of the
same name to view the data you entered.
CLEAN UP Close the PackageWeight workbook, saving your changes if you want to.