is there vba to disable printing if all cells within a range and empty?
is there vba to disable printing if all cells within a range and empty?
In the VBA editor, double-click "This Workbook" and past this code there. In this code the range of cells that can't be empty is A5 to A10, but you can change that as needed. Also, the code assumes Sheet1 is the sheet with the cells that can't be empty, so change that as needed too.
![]()
Private Sub Workbook_BeforePrint(Cancel As Boolean) Dim myrange As Range Dim mycell As Range Cancel = True Set myrange = Worksheets("Sheet1").Range("A5:A10") For Each mycell In myrange If mycell.Value <> "" Then Cancel = False Next mycell End Sub
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
with this do all cell in the range have to have data? I need it to work if only 1 has data but not run if no cells in the range have data?
This code would not print if ALL cells in the range are blank. If even just one cell in the range has data, then it will print.
how would i add a msg box to let someone know can't print until info is entered.
Use this ammended code, just change the part in the quotes (the msgbox line) to say what you want:
![]()
Private Sub Workbook_BeforePrint(Cancel As Boolean) Dim myrange As Range Dim mycell As Range Cancel = True Set myrange = Worksheets("Sheet1").Range("A5:A10") For Each mycell In myrange If mycell.Value <> "" Then Cancel = False Next mycell If Cancel = True Then MsgBox ("Can't print until all cells are filled") End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks