#1   Report Post  
Steve O
 
Posts: n/a
Default 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


  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

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
  #3   Report Post  
Steve O
 
Posts: n/a
Default

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

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

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
  #5   Report Post  
Steve O
 
Posts: n/a
Default

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 03:41 PM
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 02:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 11:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 01:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 05:46 PM


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"