Selecting sheets in Excel VBA

G

gfalc3194

If I select the first sheet in a workbook, hold shift and go to the
last sheet, all are selected for printing. However, when I record this
function, the VBA code lists all sheets by name.

For instance, If the workbook contains 'sheet1' 'sheet2' and 'sheet3'
the macro code recorded = Sheets(Array("sheet1", "sheet2",
"sheet3")).Select

I would like to know if there is a way to select from sheet1 to sheet3
without explicitly naming them. The problem is that in the actual
workbook, sometimes I add or delete sheets, and sometimes rename them
for clarity. I don't want to have to modify the macro everytime I do
that.

Any help will be greatly appreciated.
 
R

Ron de Bruin

If you want to print all sheets you can use

Worksheets.PrintOut

Or

ThisWorkbook.PrintOut
 
C

Cole

Try this see if that is what you want
sub test()
Sheets(Array(Worksheets(1).Name, Worksheets(2).Name,
Worksheets(3).Name)).Select
end sub
 
T

Tom Ogilvy

Cole shows you how to select the first 3 sheets in the tab order, even if
there are more. This could also be done with

worksheets(array(1,2,3)).select
 

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