Validation Loop Controls - VBA Userform

Jadifer

New Member
Joined
Jun 5, 2015
Messages
3
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.

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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

Could you try loading the Userform and then using an activation event to trigger this macro so that when you unload / exit sub the Userform is still displayed?

(Won't lie - I'm very new to Userforms)
Jake
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top