Hello AndyE,
I revised your macro after I figured out what you wanted to do. This macro has been added to the user form in the attached workbook.
Private Sub cmbSubmit_Click()
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Wks = Worksheets("Overtime")
'First entry starts at "A4"
Set Rng = Wks.Range("A4")
'Find the last entry in column "A"
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
'If last entry is below "A4" then use row 4. Otherwise, use the last entry row + 1
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd.Offset(1, 0))
'Make the range a single row of 12 columns
Set Rng = Rng.Resize(ColumnSize:=12)
'Write data to worksheet
If Me.cboOvertimeType.Value = "" Then
MsgBox "Please select the type of Overtime worked.", vbExclamation, "Overtime Form"
Me.cboOvertimeType.SetFocus
End If
With Rng
.Item(1).Value = RosStartDatePicker.Value
.Item(2).Value = VBA.Format(RosStartTimePicker.Value, "hh:mm:ss")
.Item(3).Value = RosEndDatePicker.Value
.Item(4).Value = VBA.Format(RosEndTimePicker.Value, "hh:mm:ss")
.Item(6).Value = ActStartDatePicker.Value
.Item(7).Value = VBA.Format(ActStartTimePicker.Value, "hh:mm:ss")
.Item(8).Value = ActEndDatePicker.Value
.Item(9).Value = VBA.Format(ActEndTimePicker.Value, "hh:mm:ss")
.Item(12).Value = cboOvertimeType.Value
End With
Unload Me
End Sub
Bookmarks