I have a Code for my user form and it works somewhat. Right now when you input the data and just stays on the same row rather than dropping to the next one.
I need it to input the data from the userform to the next available row. I know its prob somthing simple but im just missin it. Also if i can get it to fill in data by columns it would work better. Where my Heading would be in A Column and My data entry would start on B Column and Continue that way instead of going down.
Here is my Code:
Private Sub cmdSubmit_Click()
Dim RowCount As Long
Dim ctl As Control
'Check User Input
If Me.txtApparatus.Value = "" Then
MsgBox "Please enter Apparatus.", vbExclamation, "Form Error"
Me.txtApparatus.SetFocus
Exit Sub
End If
If Me.txtReporter.Value = "" Then
MsgBox "Please enter your Name.", vbExclamation, "Form Error"
Me.txtReporter.SetFocus
Exit Sub
End If
If Me.txtDate1.Value = "" Then
MsgBox "Please enter a Date.", vbExclamation, "Form Error"
Me.txtDate1.SetFocus
Exit Sub
End If
If Not IsDate(Me.txtDate1.Value) Then
MsgBox "The Date box must contain a date.", vbExclamation, "Form Error"
Me.txtDate1.SetFocus
Exit Sub
End If
'Write data to worksheet
RowCount = Worksheets("MaintLog").Range("a2").CurrentRegion.Rows.Count
With Worksheets("MaintLog").Range("A2")
.Offset(RowCount, 0).Value = Me.txtApparatus.Value
.Offset(RowCount, 1).Value = Me.txtAppearance.Value
.Offset(RowCount, 2).Value = Me.cboPriority1.Value
.Offset(RowCount, 3).Value = Me.txtMechanical.Value
.Offset(RowCount, 4).Value = Me.cboPriority2.Value
.Offset(RowCount, 5).Value = Me.txtElectrical.Value
.Offset(RowCount, 6).Value = Me.cboPriority3.Value
.Offset(RowCount, 7).Value = Me.txtReporter.Value
.Offset(RowCount, 8).Value = DateValue(Me.txtDate1.Value)
.Offset(RowCount, 9).Value = Format(Now, "dd/mm/yyyy hh:nn:ss")
End With
'Clear the form
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
Unload Me
End If
Next ctl
End Sub
Bookmarks