Trying to creat an array of All sheets in WB

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
Sub Macro2()
Dim stgSheets As String, Cnt As Long
Dim arrSheets()
Cnt = Sheets.Count
ReDim arrSheets(Cnt - 1)
For i = 1 To Cnt
stgSheets = stgSheets & Sheets(i).Name
arrSheets(i - 1) = stgSheets
'sSheets = sSheets & "", ""
Next i

'stgSheets at this point = "Sheet1Sheet2Sheet3"
'Yet I want to produce "Sheet1","Sheet2",Sheet3" inorder to pass the string
' into the one liner


'Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Does this code point you in the right direction?

Code:
Function mySheetsArr()

Dim mySheets() As Variant
Dim i As Long, j As Long

i = ThisWorkbook.Sheets.Count - 1

ReDim mySheets(i)

For j = 0 To i

    mySheets(j) = ThisWorkbook.Sheets(j + 1).Name

Next j

Sheets(mySheets).Select

End Function

Hope it helps.
 
Upvote 0
Hi Jim,

At least as you showed, you are wanting all the worksheets. Why not just:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> exampleSelectAll()<br>    ThisWorkbook.Worksheets.Select<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

By chance are you wanting to build a collection of worksheets that discludes some?

Mark
 
Upvote 0

Forum statistics

Threads
1,206,971
Messages
6,075,926
Members
446,171
Latest member
Maddogg4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top