Hello,
I have an excel sheet that has multiple line items that a user needs to check a "Required" checkbox or a "N/A" checkbox. If the "Required" checkbox is selected, then the user either needs to select a "Completed" checkbox OR fill in a comment in a cell to explain why it is not yet completed. All of the checkboxes are Form Control checkboxes and not ActiveX Control checkboxes.
I would like to prevent the user from being able to print the form unless it is filled out correctly. Basically, if the "Required" checkbox ("Check Box 161") is selected AND the "Completed" checkbox ("Check Box 4") is deselected AND there is no comment in cell J9, then cancel printing. So far, the code I have under the ThisWorkbook section is...
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Sheets("Sheet1").CheckBoxes("Check Box 161").Value = 1 And Sheets("Sheet1").CheckBoxes("Check Box 4").Value = 0 And Sheets("Sheet1").Range("J9").Value = "" Then
Cancel = True
MsgBox ("Please Insert Comment on Line 9")
End If
End Sub
I have changed the name of the sheet to sheet1 for this example, but I have the real sheet name in my code. I can get this code to work with just the J9 value section, but it won't work with form control checkbox codes. I can get it to work if I were to insert in a new ActiveX control checkboxes and use those proper names, but I would prefer not to change all of my boxes to ActiveX boxes because that will be quite a bit of code for me to change.
I have an excel sheet that has multiple line items that a user needs to check a "Required" checkbox or a "N/A" checkbox. If the "Required" checkbox is selected, then the user either needs to select a "Completed" checkbox OR fill in a comment in a cell to explain why it is not yet completed. All of the checkboxes are Form Control checkboxes and not ActiveX Control checkboxes.
I would like to prevent the user from being able to print the form unless it is filled out correctly. Basically, if the "Required" checkbox ("Check Box 161") is selected AND the "Completed" checkbox ("Check Box 4") is deselected AND there is no comment in cell J9, then cancel printing. So far, the code I have under the ThisWorkbook section is...
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Sheets("Sheet1").CheckBoxes("Check Box 161").Value = 1 And Sheets("Sheet1").CheckBoxes("Check Box 4").Value = 0 And Sheets("Sheet1").Range("J9").Value = "" Then
Cancel = True
MsgBox ("Please Insert Comment on Line 9")
End If
End Sub
I have changed the name of the sheet to sheet1 for this example, but I have the real sheet name in my code. I can get this code to work with just the J9 value section, but it won't work with form control checkbox codes. I can get it to work if I were to insert in a new ActiveX control checkboxes and use those proper names, but I would prefer not to change all of my boxes to ActiveX boxes because that will be quite a bit of code for me to change.