Create Form in Excel
'Macro to Create Form in Excel
Private Sub Cmdbutton_add_Click()
Dim iRow As Long
'find Next empty row in database
iRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
'check for a Name number
If Trim(Me.textbox_name.Value) = "" Then
Me.textbox_name.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
Sheets("Sheet1").Cells(iRow, 1) = Me.textbox_name
Sheets("Sheet1").Cells(iRow, 2) = Me.textbox_surname
Sheets("Sheet1").Cells(iRow, 3) = Me.textbox_age
Sheets("Sheet1").Cells(iRow, 4) = Me.textbox_gender
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.textbox_name.Value = ""
Me.textbox_surname.Value = ""
Me.textbox_age.Value = ""
Me.textbox_gender.Value = ""
Me.textbox_name.SetFocus
End Sub
Private Sub Cmdbutton_close_Click()
Unload Me
End Sub
Private Sub surname_Click()
End Sub
Private Sub Cmdbutton_add_Click()
Dim iRow As Long
'find Next empty row in database
iRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
'check for a Name number
If Trim(Me.textbox_name.Value) = "" Then
Me.textbox_name.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
Sheets("Sheet1").Cells(iRow, 1) = Me.textbox_name
Sheets("Sheet1").Cells(iRow, 2) = Me.textbox_surname
Sheets("Sheet1").Cells(iRow, 3) = Me.textbox_age
Sheets("Sheet1").Cells(iRow, 4) = Me.textbox_gender
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.textbox_name.Value = ""
Me.textbox_surname.Value = ""
Me.textbox_age.Value = ""
Me.textbox_gender.Value = ""
Me.textbox_name.SetFocus
End Sub
Private Sub Cmdbutton_close_Click()
Unload Me
End Sub
Private Sub surname_Click()
End Sub
Comments
Post a Comment