So I am working on a user form for our plant production process that allows the user to simply polulate needed cells and submit those values to a database and have the for reset for the next set of values. I have all functions working for the physical submittal of these values as well as the form reset though I am in process of placing checks and balances to verify that all required cells have information within them before the user is able to submit the form. I have successfully written code to check each individual cell and pop up a message if one of the values is missing, however, I cannot figure out the remaining portion of the code in which the form in its entirety is reviewed and then submitted. To try and make things easier for the complete form review I have allocated a range on a secondary sheet for the required values on the user form so that my Range is together instead of multiple sporadic cells across the form. I am using this range when trying to run my IF statement. Below is my current code, note that I have two different sections of code that I have tried. One is successful at stopping the sub it information is missing though will not follow through when complete and the other will not stop when information is missing but will follow through the submittal process.
Sub Data_Check()
'----- Checks for blank entries in required cells individually
'General Information Values
If Range("Batch_Number") = Empty Then
MsgBox "Enter Batch Number!"
End If
If Range("Part_Number") = Empty Then
MsgBox "Enter Part Number!"
End If
If Range("Laser_Number") = Empty Then
MsgBox "Enter Laser Number!"
End If
If Range("Operator_Number") = Empty Then
MsgBox "Enter Operator Number!"
End If
If Range("Shift") = Empty Then
MsgBox "Enter Shift!"
End If
' Bore Hole Values 1-3
If Range("BoreHole_Head1") = Empty Then
MsgBox "Bore Hole Head 1 Missing!"
End If
If Range("BoreHole_Head2") = Empty Then
MsgBox "Bore Hole Head 2 Missing!"
End If
If Range("BoreHole_Head3") = Empty Then
MsgBox "Bore Hole Head 3 Missing!"
End If
' Knockout Values 1-3
If Range("Knockout_Head1") = Empty Then
MsgBox "Knockout Head 1 Missing!"
End If
If Range("Knockout_Head2") = Empty Then
MsgBox "Knockout Head 2 Missing!"
End If
If Range("Knockout_Head3") = Empty Then
MsgBox "Knockout Head 3 Missing!"
End If
'Flatness Values 1-3
If Range("Flatness_Head1") = Empty Then
MsgBox "Flatness Head 1 Missing!"
End If
If Range("Flatness_Head2") = Empty Then
MsgBox "Flatness Head 2 Missing!"
End If
If Range("Flatness_Head3") = Empty Then
MsgBox "Flatness Head 3 Missing!"
End If
'Profile Shift Values 1-3
If Range("PSM_Head1") = Empty Then
MsgBox "Profile Shift Head 1 Missing!"
End If
If Range("PSM_Head2") = Empty Then
MsgBox "Profile Shift Head 2 Missing!"
End If
If Range("PSM_Head3") = Empty Then
MsgBox "Profile Shift Head 3 Missing!"
End If
'-------- Checks User Form for Empty Cells as a whole
'Call sheet in which grouped range is located
ws_output1 = "Info_Page"
'***This section(1) works for the message box to keep the sub routine from running if
' missing data but will not call next subroutine if data complete.
Dim Cell As Range
Dim CellsEmpty As Boolean
CellsEmpty = True
For Each Cell In ThisWorkbook.Sheets(ws_output1).Range("L4:L20")
MsgBox "Look"
If Cell.Value <> "0" Then
CellsEmpty = True
MsgBox "Exit"
Exit Sub
'Works to here if missing data
End If
Next
If CellsEmpty = False Then
MsgBox "False"
Call Data_Input
MsgBox "Call Data Input"
End If
'***This section(2) works for submitting data but if value missing does not stop
' routine nor display message box.
'If Sheets(ws_output1).Range("L4:L20") <> "" Then
' MsgBox "MISSING DATA!!!"
' Else
' Call Data_Input
' End If
End Sub
Sub Data_Check()
'----- Checks for blank entries in required cells individually
'General Information Values
If Range("Batch_Number") = Empty Then
MsgBox "Enter Batch Number!"
End If
If Range("Part_Number") = Empty Then
MsgBox "Enter Part Number!"
End If
If Range("Laser_Number") = Empty Then
MsgBox "Enter Laser Number!"
End If
If Range("Operator_Number") = Empty Then
MsgBox "Enter Operator Number!"
End If
If Range("Shift") = Empty Then
MsgBox "Enter Shift!"
End If
' Bore Hole Values 1-3
If Range("BoreHole_Head1") = Empty Then
MsgBox "Bore Hole Head 1 Missing!"
End If
If Range("BoreHole_Head2") = Empty Then
MsgBox "Bore Hole Head 2 Missing!"
End If
If Range("BoreHole_Head3") = Empty Then
MsgBox "Bore Hole Head 3 Missing!"
End If
' Knockout Values 1-3
If Range("Knockout_Head1") = Empty Then
MsgBox "Knockout Head 1 Missing!"
End If
If Range("Knockout_Head2") = Empty Then
MsgBox "Knockout Head 2 Missing!"
End If
If Range("Knockout_Head3") = Empty Then
MsgBox "Knockout Head 3 Missing!"
End If
'Flatness Values 1-3
If Range("Flatness_Head1") = Empty Then
MsgBox "Flatness Head 1 Missing!"
End If
If Range("Flatness_Head2") = Empty Then
MsgBox "Flatness Head 2 Missing!"
End If
If Range("Flatness_Head3") = Empty Then
MsgBox "Flatness Head 3 Missing!"
End If
'Profile Shift Values 1-3
If Range("PSM_Head1") = Empty Then
MsgBox "Profile Shift Head 1 Missing!"
End If
If Range("PSM_Head2") = Empty Then
MsgBox "Profile Shift Head 2 Missing!"
End If
If Range("PSM_Head3") = Empty Then
MsgBox "Profile Shift Head 3 Missing!"
End If
'-------- Checks User Form for Empty Cells as a whole
'Call sheet in which grouped range is located
ws_output1 = "Info_Page"
'***This section(1) works for the message box to keep the sub routine from running if
' missing data but will not call next subroutine if data complete.
Dim Cell As Range
Dim CellsEmpty As Boolean
CellsEmpty = True
For Each Cell In ThisWorkbook.Sheets(ws_output1).Range("L4:L20")
MsgBox "Look"
If Cell.Value <> "0" Then
CellsEmpty = True
MsgBox "Exit"
Exit Sub
'Works to here if missing data
End If
Next
If CellsEmpty = False Then
MsgBox "False"
Call Data_Input
MsgBox "Call Data Input"
End If
'***This section(2) works for submitting data but if value missing does not stop
' routine nor display message box.
'If Sheets(ws_output1).Range("L4:L20") <> "" Then
' MsgBox "MISSING DATA!!!"
' Else
' Call Data_Input
' End If
End Sub