Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default add worksheet to group

I am looking for a way to add a worksheet to a group of
sheets that I will print using the "printpreview" method.

I will add them if they meet certain requirements, which
I've already worked out.

I'm just looking for the method and an example to add the
sheets to the group.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default add worksheet to group

Hi Rich,

Here is some sample code to group the sheets, just change the criteria to
yours

Dim i As Long, j As Long
Dim arySheets

For i = 1 To Worksheets.Count
If Left(Worksheets(i).Name, 5) = "Sheet" Then
If j = 0 Then
ReDim arySheets(0)
Else
ReDim Preserve arySheets(j)
End If
arySheets(j) = Worksheets(i).Name
j = j + 1
End If
Next i

Worksheets(arySheets).Select

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Rich" wrote in message
...
I am looking for a way to add a worksheet to a group of
sheets that I will print using the "printpreview" method.

I will add them if they meet certain requirements, which
I've already worked out.

I'm just looking for the method and an example to add the
sheets to the group.



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default add worksheet to group

Outstanding!!

Thanks, Bob!!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default add worksheet to group

Thank you, and it is a pleasure.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
Outstanding!!

Thanks, Bob!!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Go to first empty worksheet in a certain group of sheets Roger Excel Discussion (Misc queries) 4 January 24th 08 07:41 AM
how can I group information from more than one worksheet musmik Excel Worksheet Functions 0 July 18th 06 01:58 PM
how to group records in a new worksheet Gunther Excel Worksheet Functions 1 March 1st 06 10:37 AM
how to group records in a new worksheet Gunther Excel Discussion (Misc queries) 1 February 22nd 06 06:59 AM
Group Function on a Protected Worksheet CiaraG[_4_] Excel Programming 1 December 22nd 03 04:46 PM


All times are GMT +1. The time now is 04:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"