Hi Everyone, I have had a colleague of mine state that a user form which I have created isn't always writing data into the data sheet when they use the user form. I have looked at the VBA and it seems fine to me. Could anyone please take a look and see if there is anything that I am missing?
Code:
Private Sub cmdSave_Click()
Application.ScreenUpdating = False:
Application.Calculation = xlCalculationManual
'Click Ok
Dim lRow As Long
'Error Text Box'
If Me.cmbSite = "" Then
MsgBox "Please enter a Site Name.", vbExclamation, "Staff Hours"
Me.cmbSite.SetFocus
End If
If Me.cmbName = "" Then
MsgBox "Please enter an Employee Name.", vbExclamation, "Staff Hours"
Me.cmbName.SetFocus
End If
If Me.cmbTimeIn = "" Then
MsgBox "Please enter a Time In Value.", vbExclamation, "Staff Hours"
Me.cmbTimeIn.SetFocus
End If
If Me.cmbTimeOut = "" Then
MsgBox "Please enter a Time Out Value.", vbExclamation, "Staff Hours"
Me.cmbTimeOut.SetFocus
End If
Dim ws As Worksheet
Set ws = Worksheets("Data")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = DateValue(txtDate.Value)
.Cells(lRow, 3).Value = Me.cmbSite.Value
.Cells(lRow, 4).Value = Me.cmbName.Value
.Cells(lRow, 5).Value = Me.cmbTimeIn.Value
.Cells(lRow, 6).Value = Me.cmbTimeOut.Value
.Cells(lRow, 8).Value = Me.cmbTransport.Value
.Cells(lRow, 9).Value = Me.cmbMethod.Value
.Cells(lRow, 10).Value = Me.txtTravelTime.Value
End With
'Clear input controls.
Me.cmbName.Value = ""
Me.cmbTransport.Value = ""
Me.cmbMethod.Value = ""
Me.txtTravelTime.Value = ""
Application.ScreenUpdating = True:
Application.Calculation = xlCalculationAutomatic
End Sub