Thursday, January 19, 2017

Working with Forms in MS Excel

How to create Data Input Form in Excel

01.First Design Basic Table in Excel as follows


02.Then Move to VBA mode under developer tab,And Design User form as shown in following Screen Shot


03.Once you design user form as above then you have to place following codings.


Private Sub cmdEnter_Click()

Dim emptyRow As Long

'Make Sheet1 active
Sheet1.Activate

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

'Transfer information
Cells(emptyRow, 1).Value = txtName.Value
Cells(emptyRow, 2).Value = txtAddress.Value
Cells(emptyRow, 3).Value = txtAge.Value
Cells(emptyRow, 5).Value = cmbEducation.Value



If OptionButton1.Value = True Then
    Cells(emptyRow, 4).Value = "Male"

Else
    Cells(emptyRow, 4).Value = "Female"
End If

End Sub
Private Sub UserForm_Initialize()

'Empty Name Text Box
txtName.Value = ""

'Empty Address Text Box
txtAddress.Value = ""

'Empty Education Combo
cmbEducation.Clear

'Fill Education Combo

With cmbEducation
    .AddItem "OL"
    .AddItem "AL"
    .AddItem "Degree"
End With

'Set Focus on Name Text Box
txtName.SetFocus
End Sub

04.Once you completed this step you can run the form and then enter sample data.See what happens then

website counter

No comments:

Post a Comment