PDA

View Full Version : Solved: Printing multiple pages based on cell



Emoncada
07-10-2007, 07:44 AM
I have a print/save button on a speadsheet that auto saves and brings up the Print box after it saves. I wanted to know if I can have a printform that can come up and ask me how many copies I want to print and then automatically know Which pages to print.

Example
If Cell C293 = (Any Value) and
If Cell C344 = (Any Value)
Then Print Pages 1-3

If Cell C293 = (Any Value) and
If Cell C344 = ""
Then Print Pages 1-2

If Cell C293 = "" and
If Cell C344 = ""
Then Print Page 1

Can this happen?

JimmyTheHand
07-10-2007, 08:04 AM
Hi :hi:

Printing is done with PrintOut method, like this:
ActiveSheet.PrintOut From:=1, To:=2, Copies:=2
Here you can set the range of pages (From, To), as well as number of copies (Copies). Constant numbers can be replaced by variables.
Note that pages are printed pages, not worksheets.

Jimmy

Emoncada
07-10-2007, 08:25 AM
I would like it to automatically pick which pages to print depending if those cells have values or not. Your example seems I would have it always print certain pages. Somestimes I might just need page 1, sometimes pages 1 & 2, sometimes all 3 pages.

lucas
07-10-2007, 09:13 AM
Hi Em,
Jimmy gave you the solution you need. You just need to construct an if / ElseIf or multiple case statement to deal with each instance...

lucas
07-10-2007, 09:33 AM
This should get you started:
If Range("C293").Value > "" And Range("C344").Value > "" Then
ActiveSheet.PrintOut From:=1, To:=3, Copies:=2
End If

Emoncada
07-10-2007, 09:36 AM
Thanks Lucas is there a way instead of having copies as a value have the user get prompted on how many?

lucas
07-10-2007, 09:51 AM
Dim myNum As Integer
myNum = Application.InputBox("Enter a number")
If Range("C293").Value > "" And Range("C344").Value > "" Then
ActiveSheet.PrintOut From:=1, To:=3, Copies:=myNum
End If

Emoncada
07-10-2007, 10:47 AM
Perfect Lucas Thanks. That worked great.

lucas
07-10-2007, 11:39 AM
You're welcome.....I just looked up inputbox in the vbe help...