Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Prevent worksheet print based on Cell Value

Status
Not open for further replies.

Randy11

Technical User
Oct 4, 2002
175
CA
The following code when placed in a simple 3 worksheet workbook works perfect. Unless there is a value greater than 0 in A1 the worksheet will not print. Am trying to use in a more complicated workbook and is not working? Am wanting to apply this logic to Sheet38, Sheet39, Sheet40, Sheet41, Sheet18 without success.

Code could either be added to the code that selects and prints these 5 sheets or as note below. Assistance appreciated.....

Private Sub Workbook_BeforePrint(Cancel As Boolean)

With Sheet1
If Not .Range("A1").Value > 0 Then
Cancel = True
End If
End With

End Sub
 


hi,

Assuming that this is to apply to ALL worksheets...
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    dim ws as worksheet
    for each ws in worksheets
        If Not ws.Range("A1").Value > 0 Then
            Cancel = True
        End If
    Next
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
This is still not working. Value in A1 is placed there by formula, does this make a difference? Nothing prints when 3 os the sheets meet the criteria to print. i.e. a value over 0 showing in A1?
 


Seems as if this is to apply to only the active sheet? YES???
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
        If Not ActiveSheet.Range("A1").Value > 0 Then
            Cancel = True
        End If
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top