First you have to create a procedure to trap the print event and within this procedure to write the code checking your condition, displaying the warning message, if necessary and cancel printing if the condition is not met.
In the ThisWorkbook section of your project you may use a code similar to the following one:
Obviously you have to change the sheet index and the "A1:A4" range in the code above to point to the sheet and cells you want to be tested and you may also find a better warning message to be displayed (line MsgBox("..."))Code:Sub Workbook_BeforePrint(Cancel As Boolean) Dim r As Range Set r = ThisWorkbook.Sheets(1).Range("A1:A4") For Each cell In r If IsEmpty(cell) Then MsgBox ("Fill all required cells") Cancel = True Exit For End If Next End Sub
If the cells don't form a contiguous range you have to use a cascade of IF tests for each cell like:
Hope it works.Code:If IsEmpty(ThisWorkbook.Sheets(1).Range("B1")) Then MsgBox ("Fill cell B1") Cancel = True Else If IsEmpty(ThisWorkbook.Sheets(1).Range("B3")) Then MsgBox ("Fill cell B3") Cancel = True Else If IsEmpty(ThisWorkbook.Sheets(1).Range("B5")) Then MsgBox ("Fill cell B5") Cancel = True End If End If End If


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks