I'm writing a portion of data validation for my current userform and I'm struggling to get a loop function to work properly. Currently when running the userform if you miss out a data entry it pops up with a window telling you data is missing and then unloads the userform.
I get that I need a loop function, somewhere, somehow! I just don't know what or where to put it. Any help would be greatly appreciated!
The Userform is multipage with the data spread across 3 tabs and the backdrop.
I get that I need a loop function, somewhere, somehow! I just don't know what or where to put it. Any help would be greatly appreciated!
The Userform is multipage with the data spread across 3 tabs and the backdrop.
Rich (BB code):
Private Sub cbsave_Click()
Dim totalRows As Long
Dim str As String
Dim endDate As String, startDate As String
'error check - blank UserForm fields not permitted
If txtdate.Text = "" Then
MsgBox "Please Enter Date", vbOKOnly, "Date Error!"
Exit Sub
ElseIf day.Value = False And night.Value = False Then
MsgBox "Please Select A Shift", vbOKOnly, "Shift Error!"
Exit Sub
If jumbotext.Text = "" Then
MsgBox "Please enter the jumbo number", vbOKOnly, "Jumbo Error!"
Exit Sub
If topcentre.Value = "" Or operator.Value = "" Or centre.Value = "" Or drive.Value = "" Or bottomcentre.Value = "" Then
MsgBox "Please enter all values for chop out", vbOKOnly, "Chop Out Error!"
Exit Sub
If ltc.Value = "" Or ctc.Value = "" Or htc.Value = "" Or lo.Value = "" Or co.Value = "" Or ho.Value = "" Or lc.Value = "" Or cc.Value = "" Or hc.Value = "" Or ld.Value = "" Or cd.Value = "" Or hd.Value = "" Or lbc.Value = "" Or cbc.Value = "" Or hbc.Value = "" Then
MsgBox "Please enter all values for the colour readings", vbOKOnly, "Colour Reading Error!"
Exit Sub
If product.ListIndex < 0 Then
MsgBox "Please select product name from the drop down menu", vbCritical
Exit Sub
End If
If pgrade.ListIndex < 0 Then
MsgBox "Please select the P Grade from the drop down menu", vbCritical
Exit Sub
End If
Dim emptyRow As Long
[loads correct worksheet and page here]
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 3
'Transfer information
Cells(emptyRow, 1).Value = txtdate.Value
Cells(emptyRow, 2).Value = jumbotext.Value
Cells(emptyRow, 3).Value = product.Value
Cells(emptyRow, 4).Value = pgrade.Value
If day.Value = True Then
Cells(emptyRow, 5) = "Day"
ElseIf night.Value = True Then
Cells(emptyRow, 5) = "Night"
End If
Cells(emptyRow, 6).Value = topcentre.Value
Cells(emptyRow, 7).Value = operator.Value
Cells(emptyRow, 8).Value = centre.Value
Cells(emptyRow, 9).Value = drive.Value
Cells(emptyRow, 10).Value = bottomcentre.Value
Cells(emptyRow, 11).Value = ltc.Value
Cells(emptyRow, 12).Value = ctc.Value
Cells(emptyRow, 13).Value = htc.Value
Cells(emptyRow, 14).Value = lo.Value
Cells(emptyRow, 15).Value = co.Value
Cells(emptyRow, 16).Value = ho.Value
Cells(emptyRow, 17).Value = lc.Value
Cells(emptyRow, 18).Value = cc.Value
Cells(emptyRow, 19).Value = hc.Value
Cells(emptyRow, 20).Value = ld.Value
Cells(emptyRow, 21).Value = cd.Value
Cells(emptyRow, 22).Value = hd.Value
Cells(emptyRow, 23).Value = lbc.Value
Cells(emptyRow, 24).Value = cbc.Value
Cells(emptyRow, 25).Value = hbc.Value
Cells(emptyRow, 26).Value = rtc.Value
Cells(emptyRow, 27).Value = ro.Value
Cells(emptyRow, 28).Value = rc.Value
Cells(emptyRow, 29).Value = rd.Value
Cells(emptyRow, 30).Value = rbc.Value
Workbooks(Workbooks.Count).Close SaveChanges:=True
Unload me