PDA

View Full Version : Sleeper: Print Macro Not Working



roofem
02-11-2005, 04:47 PM
Good day,
I am trying to get an if then statement regarding printing or not printing a page in a spreadsheet to work and I am stuck. Here is the scenario - I have two ranges "Yellow" and "Blue". I want to print both the Yellow and Blue ranges if a particular cell = "yes" and otherwise just print the Yellow range. Here is the coding I am currently trying to use: I created print macros (that do work) called printcombinedsections (to print yellow and blue) and printyellow section (to just print yellow)


Sub worksheet_Calculate()
If Range("c25") = "Yes" Then
printcombinedsections
Else: PrintYellowSection
End If
End Sub

Any idea would be much appreciated.

Roofem

Zack Barresse
02-11-2005, 04:56 PM
Hi Roofem, welcome to the board!!


So this doesn't work for you? Where is this routine located? In what module? And could you not shorten to just ...


Sub worksheet_Calculate()
If Range("C25") = "Yes" Then Call printcombinedsections
Call PrintYellowSection
End Sub

You may need to specify the sheet, as it's assuming it's looking at C25 of the ActiveSheet. If this is not the case, tell us what sheet this is on and post the other two codes you have.


info

Ken Puls
02-11-2005, 05:06 PM
Hi Roofem,

FYI, this event (I assume it is in the Worksheet code module?):


Sub worksheet_Calculate()

Will only fire when the worksheet is recalculated (you press F9 or change a number that forces calculation.)

Are you sure this is the way you want to trigger the code?

mdmackillop
02-11-2005, 05:24 PM
Hi Zack,
Looks to me like your code will print the Yellow section twice!
MD

Zack Barresse
02-11-2005, 05:37 PM
Hi Zack,
Looks to me like your code will print the Yellow section twice!
MD
Could, yes. If code like mine were to be used, I'd say to take out printing the "yellow" range from the first routine. This just seems that there is a better way to do these things. That's why I asked to see the entire code.

Thanks Malcolm! You shall hence forth be known to me as Eagle-Eye. ;)

johnske
02-11-2005, 06:44 PM
Hi roofem,

Your code should work if "printcombinedsections" and "PrintYellowSection" are in the same sheet module you're using the Sheet_Calculate in, or if they're in another ordinary "bas" module, but it wont work if they're in another sheet module or in 'ThisWorkbook' module.

You could then try Call printcombinedsections or, Run ("printcombinedsections") but it's best to try to avoid using code in one sheet module to run code on another sheet module - use a basic module...

HTH,
John