View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default selecting all worksheets to the right of specified worksheet


The code that Mike has provided here will always include the far left sheet
in the selection irrespective of its name (even it is sheet "DT").

If Sheets(1).Activate is omitted then the code will still include any sheet
to the left of "DT" that is already selected prior to running the code.

--
Regards,

OssieMac


"Mike H" wrote:

Hi,

Try this

This line
Sheets(1).Activate
ensures sheets are not already grouped so may not be necessary

Sub SelectSheets()
Dim ws As Worksheet
Sheets(1).Activate
For Each ws In ActiveWorkbook.Sheets
If ws.Index Worksheets("DT").Index Then
ws.Select False
End If
Next ws
End Sub


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"PVANS" wrote:

Good morning

I hope someone can help me with this:
I am trying to create a "clean master file" using a macro that the user can
run at the end of each week/month.

In order for this to happen - I need to select all the client worksheets and
delete specific ranges and rows within them. In terms of deleting the ranges
- I can do that.

However, I am unsure how to select all worksheets to the right of the
specific header worksheet called "DT" - I do not want to select the
worksheets to the left of this, as they contain invoice and master report
sheets; and of course, the number of client sheets will grow each month so I
can't simply record the macro as it will be outdated as soon as a new client
is added.

Is there a method I can use to select all worksheets that are to the right
of a specific sheet (the "DT" sheet)?

Thank you for any ideas and help given

Regards,

Paul