ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   BeforePrint macro (https://www.excelbanter.com/excel-discussion-misc-queries/46304-beforeprint-macro.html)

Steve O

BeforePrint macro
 
Hello,

I'm looking for code to check a value in a cell and if that value is 0 then
continue to print. If the value is any number other than 0 then display a
message box stating that the sheet does not balance and let the user go back
to the sheet and fix. Here is the code I have so far with no success

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("A42") < 0 Then PrintOut = False
End Sub


Thanks for any input.
Steve



Dave Peterson

How about:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If worksheets("sheet99").Range("A42") < 0 Then
cancel = true
end if
End Sub

Maybe adding a msgbox would help the user understand why his/her listings never
show up!


Steve O wrote:

Hello,

I'm looking for code to check a value in a cell and if that value is 0 then
continue to print. If the value is any number other than 0 then display a
message box stating that the sheet does not balance and let the user go back
to the sheet and fix. Here is the code I have so far with no success

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("A42") < 0 Then PrintOut = False
End Sub

Thanks for any input.
Steve


--

Dave Peterson

Steve O

Thanks Dave..

In regardsto the message box do I need to add it after the cancel = true as
an if statement also. I not able to get the message box to appear when the
true condition exists.

"Dave Peterson" wrote:

How about:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If worksheets("sheet99").Range("A42") < 0 Then
cancel = true
end if
End Sub

Maybe adding a msgbox would help the user understand why his/her listings never
show up!


Steve O wrote:

Hello,

I'm looking for code to check a value in a cell and if that value is 0 then
continue to print. If the value is any number other than 0 then display a
message box stating that the sheet does not balance and let the user go back
to the sheet and fix. Here is the code I have so far with no success

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("A42") < 0 Then PrintOut = False
End Sub

Thanks for any input.
Steve


--

Dave Peterson


Dave Peterson

You could put the msgbox line anywhere between the If/End if pair:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If worksheets("sheet99").Range("A42") < 0 Then
Msgbox "Please balance your workbook--look at sheet99 cell A42"
cancel = true
Msgbox "or you could put it here, but don't use both"
end if
End Sub

ps. I should have read your original message better. I see that you said you
wanted a msgbox added!



Steve O wrote:

Thanks Dave..

In regardsto the message box do I need to add it after the cancel = true as
an if statement also. I not able to get the message box to appear when the
true condition exists.

"Dave Peterson" wrote:

How about:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If worksheets("sheet99").Range("A42") < 0 Then
cancel = true
end if
End Sub

Maybe adding a msgbox would help the user understand why his/her listings never
show up!


Steve O wrote:

Hello,

I'm looking for code to check a value in a cell and if that value is 0 then
continue to print. If the value is any number other than 0 then display a
message box stating that the sheet does not balance and let the user go back
to the sheet and fix. Here is the code I have so far with no success

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("A42") < 0 Then PrintOut = False
End Sub

Thanks for any input.
Steve


--

Dave Peterson


--

Dave Peterson

Steve O

No trouble at all...thank you for the response it works great! I really
appreciate your help!

"Dave Peterson" wrote:

You could put the msgbox line anywhere between the If/End if pair:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If worksheets("sheet99").Range("A42") < 0 Then
Msgbox "Please balance your workbook--look at sheet99 cell A42"
cancel = true
Msgbox "or you could put it here, but don't use both"
end if
End Sub

ps. I should have read your original message better. I see that you said you
wanted a msgbox added!



Steve O wrote:

Thanks Dave..

In regardsto the message box do I need to add it after the cancel = true as
an if statement also. I not able to get the message box to appear when the
true condition exists.

"Dave Peterson" wrote:

How about:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If worksheets("sheet99").Range("A42") < 0 Then
cancel = true
end if
End Sub

Maybe adding a msgbox would help the user understand why his/her listings never
show up!


Steve O wrote:

Hello,

I'm looking for code to check a value in a cell and if that value is 0 then
continue to print. If the value is any number other than 0 then display a
message box stating that the sheet does not balance and let the user go back
to the sheet and fix. Here is the code I have so far with no success

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("A42") < 0 Then PrintOut = False
End Sub

Thanks for any input.
Steve

--

Dave Peterson


--

Dave Peterson



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

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