Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Default A simple printing pages depending on cell value

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 259
Default A simple printing pages depending on cell value

I was having a further think about this and considered that it may be
useful to return [Z1].value to zero once the print has been passed to
the printer and you have returned to the Main Sheet, this would force
user to select their required amounts eliminating un-necessary waste
should the user forget to change down a higher amount.

Also I put an error message in it that alerts the user they need to
enter a value of 1 to 40 in the event they leave the cell with zero(0)

This code has been tested and you can copy/paste directly as I copied it
directly from my VBE window.

HTH
Mick.

Sub PRINT_GENERIC()

Dim Gsht As Worksheet, Msht As Worksheet
Dim a As Range
Dim Oops As Integer

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

If a.Value 0 Then
Gsht.PrintOut From:=1, To:=a, Copies:=1
Else
Oops = MsgBox("You must enter a value between 1 & 40", vbOKOnly)
Exit Sub
End If

a.Value = 0

Msht.Activate

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default A simple printing pages depending on cell value

Mick,
Since vbOkOnly is the default button for MsgBox, you don't need to code
for it. Specifying button[s] is only necessary if you want others than
the default!<g

I might suggest (if I may) that you could also implement some way of
not hard-coding the To:= parameter. Perhaps the user could just select
the last row and your code could use that instead...

To:=Selection.Row

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
Excel 2003 printing problem--printing 1 document on 2 pages Bons Excel Discussion (Misc queries) 0 December 24th 09 04:15 PM
how to skip printing pages in exel by cell value Barry Excel Programming 2 August 6th 08 05:11 PM
Printing x amount of pages if cell is greater than 0 privater Excel Programming 0 February 2nd 08 10:01 AM
How do I delete pages in Excel? Keeps printing blank pages at end. Jojobean Charts and Charting in Excel 1 May 31st 07 07:37 AM
Printing Multiple Pages Based on Different Cell Criteria Nic W Excel Programming 1 September 20th 05 05:34 PM


All times are GMT +1. The time now is 12:39 PM.

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"