Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
macro with F9 | Excel Discussion (Misc queries) | |||
Help with macro looping and color query function | Excel Discussion (Misc queries) | |||
Playing a macro from another workbook | Excel Discussion (Misc queries) | |||
Date macro | Excel Discussion (Misc queries) | |||
Macro and If Statement | Excel Discussion (Misc queries) |