Macro for Print page 1 thru x

T

Tami

can i write a macro to print page 1 thru x, with the x as a cell value for
the user to input....for example some people want to print 1 thru 3, 1 thru
6, 1 thru 9....i just want them to key the 3 or 6 or 9 or whatever and the
print macro refers to it.
thanks for any help you can provide.
t
 
A

AltaEgo

Two examples to get you started... and an alternative.

Macro 1 will use the value stored in Sheet 1. No matter which sheet the use
has opened.
Macro 2 will use the value stored in A1 in whatever sheet happens to be
active at the time.

Sub Macro1()

Dim xPages

xPages = Worksheets("Sheet1").Range("A1") 'Value stored Sheet 1, cell A1

' print out active sheet. This is not necessarily Sheet1

ActiveSheet.PrintOut From:=1, To:=xPages, Copies:=1

End Sub


Sub Macro2()

Dim xPages

xPages = ActiveSheet.Range("A1") 'Value stored in current sheet, cell A1

' print out active sheet.

ActiveSheet.PrintOut From:=1, To:=xPages, Copies:=1

End Sub


The alternative would be to use InputBox to ask the user how many pages,
he/she wants printed.

Sub MacroAskUser()

Dim Message, Title, Default, xPages
Message = "How many pages do you wish to print?"
Title = "Print request"
Default = "1" ' Set default.

xPages = InputBox(Message, Title, Default)

ActiveSheet.PrintOut From:=1, To:=xPages, Copies:=1

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top