Good day Everyone
Hope the week is treating everyone well so far.
I have a VBA code for a user form that is running extremely slow. The code is as follows:
I have another form that runs super smoothly in the same workbook, the forms are not linked and reports to different sheets.
Any help would be appreciated.
Thanks
Hope the week is treating everyone well so far.
I have a VBA code for a user form that is running extremely slow. The code is as follows:
Code:
Private Sub cmdaddentry_Click()
Dim Rowcount As Long
Dim ctl As Control
If Me.txtshift.Value = "" Then
MsgBox "Please enter a Shift.", vbExclamation, "WASA_datainput"
Me.txtshift.SetFocus
Exit Sub
End If
If Me.chkmachine.Value = "" Then
MsgBox "Please enter a Machine.", vbExclamation, "WASA_datainput"
Me.chkmachine.SetFocus
Exit Sub
End If
If Me.txtdate.Value = "" Then
MsgBox "Please enter a Date.", vbExclamation, "WASA_datainput"
Me.txtdate.SetFocus
Exit Sub
End If
If Me.txtshift.Value = "" Then
MsgBox "Please enter a Shift.", vbExclamation, "WASA_datainput"
Me.txtshift.SetFocus
Exit Sub
End If
If Me.txtstart.Value = "" Then
MsgBox "Please enter a Start.", vbExclamation, "WASA_datainput"
Me.txtstart.SetFocus
Exit Sub
End If
If Me.txtstop.Value = "" Then
MsgBox "Please enter a Stop.", vbExclamation, "WASA_datainput"
Me.txtstop.SetFocus
Exit Sub
End If
' Write data to worksheet
Rowcount = Worksheets("Data capture").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Data capture").Range("A1")
.Offset(Rowcount, 0).Value = Me.txtdate.Value
.Offset(Rowcount, 1).Value = Me.txtshift.Value
.Offset(Rowcount, 2).Value = Me.txtstart.Value
.Offset(Rowcount, 3).Value = Me.txtstop.Value
.Offset(Rowcount, 5).Value = Me.chkmachine.Value
.Offset(Rowcount, 6).Value = Me.txtpops.Value
.Offset(Rowcount, 7).Value = Me.txtbobbins.Value
.Offset(Rowcount, 9).Value = Me.txtspools.Value
.Offset(Rowcount, 10).Value = Me.txtcoils.Value
.Offset(Rowcount, 11).Value = Me.txtkilograms.Value
.Offset(Rowcount, 12).Value = Me.txtproduct.Value
.Offset(Rowcount, 13).Value = Me.txttimestart.Value
.Offset(Rowcount, 14).Value = Me.txttimestop.Value
.Offset(Rowcount, 15).Value = Me.txtstrip.Value
End With
' Clear the form
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
End If
Next ctl
End Sub
Private Sub cmdcancel_Click()
Unload Me
End Sub
Private Sub cmdclear_Click()
' Clear the form
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
End If
Next ctl
End Sub
I have another form that runs super smoothly in the same workbook, the forms are not linked and reports to different sheets.
Any help would be appreciated.
Thanks