View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Trevor Shuttleworth Trevor Shuttleworth is offline
external usenet poster
 
Posts: 1,089
Default select/group sheets dependent on criteria

Hi all, I wonder if you could offer some advice, please.

I am generating a number of worksheets within a workbook. I then want to
group some of them and copy them to another workbook. The names of the
worksheets I am interested in all end in "DWM".

If I manually select the sheets and record the actions, I get:

Sheets(Array("Sunderland DWM", "Manchester DWM", "Coventry DWM")).Select


So, I thought, I just need to loop through the sheets and build the string
....

Dim ArrayList as String
For Each Sheet In Sheets
If Right(Sheet.Name, 3) = "DWM" And Sheet.Name < "Blank DWM" Then
If ArrayList = "" Then
ArrayList = """" & Sheet.Name & """"
Else
ArrayList = ArrayList & ", " & """" & Sheet.Name & """"
End If
End If
Next

But, when I try to select the sheets based on the string I have built up ...

Sheets(Array(ArrayList)).Select

.... I get Run-time error '9': Subscript out of range

ArrayList contains: "Sunderland DWM", "Manchester DWM", "Coventry DWM"

Any suggestions as to how to get this to work ... or offer a better way ?

Thanks and Regards

Trevor