Code for selecting certain worksheets

D

Dave Rey

Hi

I currently have a workbook containing many (70+)
worksheets.

I am a beginner at Visual Basic programming, but I am
trying to include in a macro a function that will select a
selection of worksheets on which I can perform certain
tasks.

The macro recorder uses the array command, but names each
sheet to be included in the selection.

What I am trying to do is use something like the array
command, but tell it to select a starting sheet -
say "Sheetstart" - and all sheets up to either a finish
sheet - "Sheetend" - or up to the last worksheet. I
continually add and remove sheets from the workbook, so do
not want to have to include the names of each sheet to be
selected in the array formula.

Can anyone help?

Thanks in advance

Dave
 
F

Frank Kabel

Hi
try something like
dim wks as worksheets
for each wks in worksheets
msgbox wks.name
next
 
D

Dave Rey

Hi

Not sure I understand how to make that work, or whether it
will do what I want.

What I am really after is the correct code to include in a
macro to achieve this:

In a workbook with 70 sheets named Sheet1 to Sheet70, I
want to select only Sheets 15 to 40.

Something like:

Sheets ("Sheet15" to "Sheet40").Select

Or in another case:

Sheets("Sheet15 to "last sheet").Select - where last sheet
could be any number depending on how many I add or delete
in the middle.

Thanks
 

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