View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ramses[_2_] Ramses[_2_] is offline
external usenet poster
 
Posts: 1
Default add worksheet to group

Hi

Try this code.
Exclude the sheets who should not be selected with your code, and ad
them into the "non selectable" array:

Option Explicit

Sub Group_Selected_Sheets_in_Array_for_Printout()
'by Ramses
'Define Worksheets for a group
Dim vWorksheet As Worksheet
Dim vWorksheetsToSelect() As String
Dim vWorksheetsToDeselect(2) As String
Dim i As Byte
Dim ii As Byte
Dim vFound As Boolean
'Define Sheet who should not selected into group
vWorksheetsToDeselect(0) = "Sheets1"
vWorksheetsToDeselect(1) = "Sheets2"
vWorksheetsToDeselect(2) = "Sheets3"
ii = 0
'All other Sheets will be selected
For Each vWorksheet In Worksheets
vFound = False
For i = 0 To UBound(vWorksheetsToDeselect)
If vWorksheet.Name = vWorksheetsToDeselect(i) Then
vFound = True
Exit For
End If
Next i
If Not vFound Then
ReDim Preserve vWorksheetsToSelect(ii)
vWorksheetsToSelect(ii) = vWorksheet.Name
ii = ii + 1
End If
Next vWorksheet
'Select Sheets in Array
Sheets(vWorksheetsToSelect).Select
End Sub

If you have more than 255 sheets in your workbook, change Type of i an
ii from Byte into Integer ;-)

Best regards from switzerland :-

--
Message posted from http://www.ExcelForum.com