Sub ArrayExample()
'Variable types defined
Dim myArray As Sheets
Dim sh As Worksheet
'Variable defined
Set myArray = Worksheets(Array("Sheet2", "Sheet1"))
'Use the variable
For Each sh In myArray
MsgBox sh.Name
Next
End Sub
Hi Luke
Not sure if this is what I'm after - maybe I wasn't clear enough.
On a Worksheet I want to have a list in A1:A3 - "Sheet1", "Sheet2", "Sheet3". I want to name this range "ArrayList"
I then want to use this name "ArrayList" in the code to replace all the sheets as I may have 30 sheets in the array and it won't be all the sheets in the Workbook.
I believe you would need to populate the array from the range. Something like this should work:
Code:
Sub SheetArrays()
Dim myRange As Range
Dim myArray As Sheets
Dim sh As Worksheet
Dim myArrayNames()
'Where is the range of cells
Set myRange = Worksheets("Sheet3").Range("A1:A2")
x = myRange.Cells.Count
'Setup our array to be populated
ReDim myArrayNames(1 To x)
'Load the array with names
For i = 1 To myRange.Cells.Count
myArrayNames(i) = myRange.Cells(i).Value
Next
'Example of using this array
Set myArray = Worksheets(myArrayNames)
For Each sh In myArray
MsgBox sh.Name
Next
End Sub