I've currently made a user form which is used to add data into a data sheet. This was working fine up until recently when it has started taking 15 seconds to write data after the user presses save. I presume it is related to the VBA code running in an inefficient manner. The code is as follows:
Code:
Private Sub cmdSave_Click()
'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 = Me.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.txtDate.Value = ""
Me.cmbSite.Value = ""
Me.cmbName.Value = ""
Me.cmbTimeIn.Value = ""
Me.cmbTimeOut.Value = ""
Me.cmbTransport.Value = ""
Me.cmbMethod.Value = ""
Me.txtTravelTime.Value = ""
End Sub