|
Question : Prevent printing if specific cells are empty
|
|
I have an excel form for users to fill-in. I need to prevent users from printing if specific cells are empty.
|
|
Answer : Prevent printing if specific cells are empty
|
|
perhaps you can use a macro liek this one. It checks if the cells in the range: A1,A4,A6,B10 are empty. If yes then cancel the job.
Private Sub Workbook_BeforePrint(Cancel As Boolean) Set rg = Intersect(ActiveSheet.UsedRange, ActiveSheet.Range("A1,A4,A6,B10")) If rg Is Nothing Then Exit Sub For Each cel In rg If cel = "" Then MsgBox "You didn't fill in all Cells!" Cancel = True Exit Sub End If
Next End Sub
To use this code: 1. open VBA editor (ALT+F11) 2. double click on ThisWorkbook code pane 3. insert code 4. go back to excel
currently it looks at all worksheets. If you need this to work on one specific worksheet then this might be an option where it checks if sheet called: Sheet2 is the active sheet
Private Sub Workbook_BeforePrint(Cancel As Boolean) Set rg = Intersect(ActiveSheet.UsedRange, ActiveSheet.Range("A1,A4,A6,B10")) If rg Is Nothing Then Exit Sub If ActiveSheet.Name = "Sheet2" Then For Each cel In rg If cel = "" Then MsgBox "You didn't fill in all Cells!" Cancel = True Exit Sub End If
Next End If End Sub
regards, Jeroen
|
|
|
|