Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JJ JJ is offline
external usenet poster
 
Posts: 122
Default Sheets Array Selection

I would like to select all sheets specified in a cell range. The sheets
needed to be selected change on differenet criteria, so I have used a formula
to concatenate the sheet names that need to be selected. In the VBA I defined
that cell as a string and then used the sheets(array(x)).select.

Here is an example:
Workbook contains 3 sheets named: "Test 1", "Test 2", and "Test 3"

The value in "Test 1" Range A1 = "Test 2", "Test 3"


Sub SelectSheetsMacro ()

Sheets("Test 1").Select

Dim x as string
x = Range("A1")

Sheets(Array(x)).Select

End Sub

I continue to get an error message....please help..


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Sheets Array Selection

You can't do it that way

Sub SelectSheets()
Dim i As Long
Dim v() As Variant
ReDim v(0 To 0)
i = 1
With Worksheets("Sheet1")
Do While Not IsEmpty(.Cells(i, 1))
ReDim Preserve v(0 To i - 1)
v(i - 1) = .Cells(i, 1).Value
i = i + 1
Loop
End With
Worksheets(v).Select
End Sub

worked for me. Assumes you will have at least two sheet names and that the
first sheet name is in cell A1 of sheet1 with the remainder following
immediately below it in column A.
--
Regards,
Tom Ogilvy



"JJ" wrote:

I would like to select all sheets specified in a cell range. The sheets
needed to be selected change on differenet criteria, so I have used a formula
to concatenate the sheet names that need to be selected. In the VBA I defined
that cell as a string and then used the sheets(array(x)).select.

Here is an example:
Workbook contains 3 sheets named: "Test 1", "Test 2", and "Test 3"

The value in "Test 1" Range A1 = "Test 2", "Test 3"


Sub SelectSheetsMacro ()

Sheets("Test 1").Select

Dim x as string
x = Range("A1")

Sheets(Array(x)).Select

End Sub

I continue to get an error message....please help..


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
Array with multiple selection criteria Robert Robinson Excel Worksheet Functions 9 March 31st 09 01:17 AM
combining cells and array from different sheets into an array to pass to IRR() [email protected] Excel Discussion (Misc queries) 3 September 11th 06 07:17 AM
Selection or Recordset to Array Witek[_2_] Excel Programming 1 April 23rd 05 07:25 PM
cells not changing selection after sheets array Simon Lloyd[_477_] Excel Programming 4 June 9th 04 03:23 PM
reading an arbitrary selection into a 1D array Jamie Martin[_2_] Excel Programming 5 September 30th 03 05:25 PM


All times are GMT +1. The time now is 09:21 AM.

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"