View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
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.