ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   conditional printing (https://www.excelbanter.com/excel-discussion-misc-queries/202525-conditional-printing.html)

Conditional printing

conditional printing
 
Is it possible to prevent printing based on zero value in a particular cell?

Don Guillett

conditional printing
 
Put this in the ThisWorkbook module. Change sheet and cell to suit.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Sheets("sheet6")
If Len(Trim(.Range("c1"))) < 1 Then Cancel = True
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Conditional printing" <Conditional

wrote in message ...
Is it possible to prevent printing based on zero value in a particular
cell?



Kevin B

conditional printing
 
You can verify the value in the cell with the workbooks BeforePrint event.

Press Alt+F11 to open the Visual Basic Editor. In the project Explorer in
the upper-left pane, doiuble click on the ThisWorkbook icon.

In the combobox at the top of the module on the left, change the object to
workbook, and the in the combobox on the right change the event to the
BeforePrint event. Use something like to following code to control the
printing, substituting the worksheet index number with either the name of the
worksheet as a string or its index number, and the cell address A1 to the
cell that contains the value you wish to verify:

Private Sub Workbook_BeforePrint(Cancel As Boolean)

If ThisWorkbook.Worksheets(1).Range("A1").Value = 0 Then
MsgBox "There is nothing to print at this time."
End If

Cancel = True

End Sub
--
Kevin Backmann


"Conditional printing" wrote:

Is it possible to prevent printing based on zero value in a particular cell?


JMay

conditional printing
 
Paste this into your ThisWorkbook Code Window << Change as necessary

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("C4") = "" Then
MsgBox "Cell C4 is empty"
Cancel = True
End If
End Sub

"Conditional printing" wrote:

Is it possible to prevent printing based on zero value in a particular cell?


JMay

conditional printing
 
better make that line...

If Range("C4") = 0 Then

Sorry

"Conditional printing" wrote:

Is it possible to prevent printing based on zero value in a particular cell?



All times are GMT +1. The time now is 08:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com