Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DRK DRK is offline
external usenet poster
 
Posts: 40
Default Building an array of worksheets for printing

I have one array that I use for printing a subset of worksheets in a
workbook. Baseline array is defined as:

Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select

Depending on various Booleans I need to add other worksheets to the above.
Inclusion of these other worksheets is dependent on Booleans.

So if BoolBSIB is TRUE, then I need to add "PolicyValuesLedgerGuarGSIB", to
the above array BEFORE I get to the "PolicyValuesLedgerGuar", _

So it should read
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuarGSIB", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select


I'm stymied on how to build up this array inside of VBA. There are three
other worksheets that may or may not get printed. How can i do this inside of
VBA?

I'd hate to brute force it by building each potential variation but...I'd
prefer a more elegant solution.

--
DRK
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Building an array of worksheets for printing

Instead of an array have you considered using a collection instead, something
like

Dim MySheets As Collection

Sub addsheets()
Dim wks As Worksheet
Set MySheets = New Collection

MySheets.Add Sheet1, Sheet1.Name
MySheets.Add Sheet2, Sheet2.Name
For Each wks In MySheets
MsgBox wks.Name
Next wks

End Sub

You can add to the collection based on the booleans and then traverse the
collection in exactly the same manner as the worksheets object (which is
mostly just a collection of worksheets).
--
HTH...

Jim Thomlinson


"DRK" wrote:

I have one array that I use for printing a subset of worksheets in a
workbook. Baseline array is defined as:

Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select

Depending on various Booleans I need to add other worksheets to the above.
Inclusion of these other worksheets is dependent on Booleans.

So if BoolBSIB is TRUE, then I need to add "PolicyValuesLedgerGuarGSIB", to
the above array BEFORE I get to the "PolicyValuesLedgerGuar", _

So it should read
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuarGSIB", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select


I'm stymied on how to build up this array inside of VBA. There are three
other worksheets that may or may not get printed. How can i do this inside of
VBA?

I'd hate to brute force it by building each potential variation but...I'd
prefer a more elegant solution.

--
DRK

  #3   Report Post  
Posted to microsoft.public.excel.programming
DRK DRK is offline
external usenet poster
 
Posts: 40
Default Building an array of worksheets for printing

Jim - I'll give it a shot tomorrow. I've been here since 6 AM, it's now after
7PM and I can't see straight anymore. I'll be back in by 6 AM.

Thanks
--
DRK


"Jim Thomlinson" wrote:

Instead of an array have you considered using a collection instead, something
like

Dim MySheets As Collection

Sub addsheets()
Dim wks As Worksheet
Set MySheets = New Collection

MySheets.Add Sheet1, Sheet1.Name
MySheets.Add Sheet2, Sheet2.Name
For Each wks In MySheets
MsgBox wks.Name
Next wks

End Sub

You can add to the collection based on the booleans and then traverse the
collection in exactly the same manner as the worksheets object (which is
mostly just a collection of worksheets).
--
HTH...

Jim Thomlinson


"DRK" wrote:

I have one array that I use for printing a subset of worksheets in a
workbook. Baseline array is defined as:

Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select

Depending on various Booleans I need to add other worksheets to the above.
Inclusion of these other worksheets is dependent on Booleans.

So if BoolBSIB is TRUE, then I need to add "PolicyValuesLedgerGuarGSIB", to
the above array BEFORE I get to the "PolicyValuesLedgerGuar", _

So it should read
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuarGSIB", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select


I'm stymied on how to build up this array inside of VBA. There are three
other worksheets that may or may not get printed. How can i do this inside of
VBA?

I'd hate to brute force it by building each potential variation but...I'd
prefer a more elegant solution.

--
DRK

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Building an array of worksheets for printing

Two techniques, either of which you can adapt to your specific needs.

sheets(1).select
sheets(3).select false
to select the first and the 3rd sheet in the workbook

or, the following selects every alternate sheet in the workbook.

Option Explicit

Sub PrintMultiSheets()
Dim x(), i As Integer
ReDim x(0)
With ActiveWorkbook.Sheets
For i = 1 To .Count Step 2
x(UBound(x)) = .Item(i).Name
ReDim Preserve x(UBound(x) + 1)
Next i
End With
ReDim Preserve x(UBound(x) - 1)
Sheets(x).Select
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I have one array that I use for printing a subset of worksheets in a
workbook. Baseline array is defined as:

Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select

Depending on various Booleans I need to add other worksheets to the above.
Inclusion of these other worksheets is dependent on Booleans.

So if BoolBSIB is TRUE, then I need to add "PolicyValuesLedgerGuarGSIB", to
the above array BEFORE I get to the "PolicyValuesLedgerGuar", _

So it should read
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuarGSIB", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select


I'm stymied on how to build up this array inside of VBA. There are three
other worksheets that may or may not get printed. How can i do this inside of
VBA?

I'd hate to brute force it by building each potential variation but...I'd
prefer a more elegant solution.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Building an array of worksheets for printing

As a point of interest would there be any advantage to using the this code
over creating a collection? I just find collections kinda handy for this sort
of thing, but I am always open to suggestions.
--
HTH...

Jim Thomlinson


"Tushar Mehta" wrote:

Two techniques, either of which you can adapt to your specific needs.

sheets(1).select
sheets(3).select false
to select the first and the 3rd sheet in the workbook

or, the following selects every alternate sheet in the workbook.

Option Explicit

Sub PrintMultiSheets()
Dim x(), i As Integer
ReDim x(0)
With ActiveWorkbook.Sheets
For i = 1 To .Count Step 2
x(UBound(x)) = .Item(i).Name
ReDim Preserve x(UBound(x) + 1)
Next i
End With
ReDim Preserve x(UBound(x) - 1)
Sheets(x).Select
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I have one array that I use for printing a subset of worksheets in a
workbook. Baseline array is defined as:

Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select

Depending on various Booleans I need to add other worksheets to the above.
Inclusion of these other worksheets is dependent on Booleans.

So if BoolBSIB is TRUE, then I need to add "PolicyValuesLedgerGuarGSIB", to
the above array BEFORE I get to the "PolicyValuesLedgerGuar", _

So it should read
Sheets(Array("Cover", "AboutThisIllustration", "PolicyValuesLedger", _
"PolicyValuesLedgerGuarGSIB", _
"PolicyValuesLedgerGuar", _
"PolicyValuesLedgerNonGuar")).Select


I'm stymied on how to build up this array inside of VBA. There are three
other worksheets that may or may not get printed. How can i do this inside of
VBA?

I'd hate to brute force it by building each potential variation but...I'd
prefer a more elegant solution.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Building an array of worksheets for printing

In article ,
says...
As a point of interest would there be any advantage to using the this code
over creating a collection? I just find collections kinda handy for this sort
of thing, but I am always open to suggestions.

Because Sheets({collection variable}).Select doesn't work? ;-)

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
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
Reference(s) to worksheets for building graphs PvZ Excel Worksheet Functions 4 June 1st 10 01:08 PM
printing an array of worksheets Marco de Witte Excel Discussion (Misc queries) 4 December 8th 04 03:21 PM
Building an Array Otto Moehrbach[_6_] Excel Programming 5 September 24th 04 01:30 PM
Building/Creating an Array Rich Cooper Excel Programming 8 May 26th 04 06:57 PM
Sheets(array) method for printing grouped worksheets Tom Ogilvy Excel Programming 0 July 17th 03 09:11 PM


All times are GMT +1. The time now is 11:36 PM.

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

About Us

"It's about Microsoft Excel"