Excel VBA UserForm
In this example we'll create a simple UI form with basic controls and use it to fill an excel sheet with values from it.
now use the toolbox to create the controls on the user form and use the properties windows to modify them to match the picture below:
now double click anywhere inside the user form (care full not to double click on a control just in an empty sot), use Ctrl + A to highlight everything and hit delete.
now write the following code:
Private Sub CommandButton1_Click()
Cells(2, 1).Value = TextBox1.Text
Cells(2, 2).Value = ComboBox1.Text
If OptionButton1.Value = True Then
Cells(2, 3).Value = "yes"
Cells(2, 3).Value = "No"
Private Sub UserForm_Initialize()
now in the Visual Basic windows double click on sheet1 and write the following code
close the VB window and go back to excel, click on Macros in developer tab
this will assign the keyboard shortcut Ctrl + j to run thee macro
now hit Ctrl + j the user form will appear.
fill in the textbox and other controls and then hit the button on the user form,
and this is the result:
Published by MaxStart
Latest update on April 9, 2015 at 04:12 AM by jak58.