View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vacuum Sealed Vacuum Sealed is offline
external usenet poster
 
Posts: 259
Default A simple printing pages depending on cell value

On 9/05/2012 1:06 AM, antonywalsh wrote:
I hope someone can help because this is driving me absolutely bonkers.
This should be something so easy yet....

I am trying to print a number of pages depending on a cell value which
is a value of a formulae.


Code:
--------------------
Sub PRINT_GENERIC()

Sheets("GENERIC").Select
a = Range("Z1").Value
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=a, Copies:=1
Sheets("MAINSHEET").Select

End Sub
--------------------


The whole worksheet has page breaks in it to make 40 pages. Every time
the above macro is run it will print 40 pages regardless of the value of
(a).

What am I doing wrong?

Thanks




You could try.

Sub PRINT_GENERIC()

Dim Gsht as worksheet, Msht as Worksheet
Dim a as Range

Set Gsht = Sheets("GENRERIC")
Set Msht = Sheets("MAINSHEET")
Set a = [Z1]

Gsht.PrintOut From:=1, To:=a, Copies:=1

Msht.Activate

End Sub

HTH
Mick.