Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The following code selects contiguous worksheets 5 through 11.
============ Sub SelectSheets() Dim Sh() As Variant, wks As Worksheet, i As Integer i = 0 For Each wks In ActiveWorkbook.Sheets If wks.Range("E2") = 1 Then i = i + 1 ReDim Preserve Sh(1 To i) Sh(i) = wks.Name End If Next Worksheets(Sh()).Select End Sub =============== I would like to add one noncontiguous worksheet (#32) to the array of selected worksheets. Is there a way to do so? Barney Byrd |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi, try this...
Worth noting the If you absolutely want the Array to start at 1 not 0 then move the line i=i+1 above the Redim Preserve Statement.. Sub SelectSheets() Dim Sh() As Long, wks As Worksheet, i As Integer For Each wks In ActiveWorkbook.Sheets If wks.Range("E2").Value = 1 Or wks.Index = 32 Then ReDim Preserve Sh(i) '''No Need for 1 to i. '''If you want your arrays to start at 1 then you can use Option Base 1 '''in Declarations section of code Sh(i) = wks.Index i = i + 1 End If Next Worksheets(Sh()).Select End Sub Hth, O |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Barney,
Something like this... '--------------------------------- Sub SelectSheets() Dim Sh() As String Dim wks As Worksheet Dim i As Long ReDim Sh(1 To Sheets.Count) For Each wks In ActiveWorkbook.Sheets If wks.Range("E2") = 1 Then i = i + 1 Sh(i) = wks.Name End If Next Sh(i + 1) = Sheets(32).Name ReDim Preserve Sh(1 To i + 1) Worksheets(Sh()).Select End Sub '--------------------------------------- Regards, Jim Cone San Francisco, USA "Barney Byrd" wrote in message ... The following code selects contiguous worksheets 5 through 11. ============ Sub SelectSheets() Dim Sh() As Variant, wks As Worksheet, i As Integer i = 0 For Each wks In ActiveWorkbook.Sheets If wks.Range("E2") = 1 Then i = i + 1 ReDim Preserve Sh(1 To i) Sh(i) = wks.Name End If Next Worksheets(Sh()).Select End Sub =============== I would like to add one noncontiguous worksheet (#32) to the array of selected worksheets. Is there a way to do so? Barney Byrd |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks to both of you, Jim and OJ. With your help I was able to resolve my
problem. Barney Byrd "Jim Cone" wrote in message ... Barney, Something like this... '--------------------------------- Sub SelectSheets() Dim Sh() As String Dim wks As Worksheet Dim i As Long ReDim Sh(1 To Sheets.Count) For Each wks In ActiveWorkbook.Sheets If wks.Range("E2") = 1 Then i = i + 1 Sh(i) = wks.Name End If Next Sh(i + 1) = Sheets(32).Name ReDim Preserve Sh(1 To i + 1) Worksheets(Sh()).Select End Sub '--------------------------------------- Regards, Jim Cone San Francisco, USA "Barney Byrd" wrote in message ... The following code selects contiguous worksheets 5 through 11. ============ Sub SelectSheets() Dim Sh() As Variant, wks As Worksheet, i As Integer i = 0 For Each wks In ActiveWorkbook.Sheets If wks.Range("E2") = 1 Then i = i + 1 ReDim Preserve Sh(1 To i) Sh(i) = wks.Name End If Next Worksheets(Sh()).Select End Sub =============== I would like to add one noncontiguous worksheet (#32) to the array of selected worksheets. Is there a way to do so? Barney Byrd |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Or you can skip the option declaration and explicitly declare where you want
it to start like you were already doing. Obviously such choices represent personal preference. -- Regards, Tom Ogilvy "OJ" wrote in message oups.com... Hi, try this... Worth noting the If you absolutely want the Array to start at 1 not 0 then move the line i=i+1 above the Redim Preserve Statement.. Sub SelectSheets() Dim Sh() As Long, wks As Worksheet, i As Integer For Each wks In ActiveWorkbook.Sheets If wks.Range("E2").Value = 1 Or wks.Index = 32 Then ReDim Preserve Sh(i) '''No Need for 1 to i. '''If you want your arrays to start at 1 then you can use Option Base 1 '''in Declarations section of code Sh(i) = wks.Index i = i + 1 End If Next Worksheets(Sh()).Select End Sub Hth, O |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I write an array to include all worksheets in a workbook? | Excel Worksheet Functions | |||
how do I include multiple worksheets to a countif formula? | Excel Discussion (Misc queries) | |||
include criteria to 'rank based array function' | Excel Discussion (Misc queries) | |||
How to Include exl charts from closed worksheets into PPT slides | Excel Programming | |||
Is it possible to include Excel worksheets/workbooks into COM Addins ? | Excel Programming |