Print macro

B

brianwa

I have a workbook that contains worksheets Jan - Feb, YTD Summary and
Summary by Quarter.

I would like to create a macro that will allow me to choose a range o
sheets to print (ie Jan - March)

Any help would be appreciated.

Thanks in advance.
B
 
D

Don Guillett

Actually this might be easier. It uses the index number of the sheet

Sub PrintSelectedSheets()
x = InputBox("first sheet to print")
y = InputBox("last sheet to print")

For Each ws In Worksheets
If ws.Index >= Worksheets(x).Index And _
ws.Index <= Worksheets(y).Index Then
ws.PrintOut
End If
Next
End Sub
 
T

Tom Ogilvy

this will work if there are only worksheets in the workbook or the first 12
sheets are the sheets of interest.

It there are chartsheets or other type sheets at the beginning or
intermingled, it won't work. ws.Index returns an index into the Sheets
collection, not the worksheets collection.

--
Regards,
Tom Ogilvy

Don Guillett said:
Actually this might be easier. It uses the index number of the sheet

Sub PrintSelectedSheets()
x = InputBox("first sheet to print")
y = InputBox("last sheet to print")

For Each ws In Worksheets
If ws.Index >= Worksheets(x).Index And _
ws.Index <= Worksheets(y).Index Then
ws.PrintOut
End If
Next
End Sub
 
N

Norman Jones

Hi Tom,

Don's code works for me whether the workbook includes intermingled
non-worksheet sheets or not.
Whilst ws.Index returns an index into the Sheets collection, since the ws
variable is restricted to the Worksheets sub-collection, the presence of
other sheet types causes no problem.

---
Regards,
Norman


Tom Ogilvy said:
this will work if there are only worksheets in the workbook or the first 12
sheets are the sheets of interest.

It there are chartsheets or other type sheets at the beginning or
intermingled, it won't work. ws.Index returns an index into the Sheets
collection, not the worksheets collection.
 

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