• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to store SELECTED SHEET NAMES in to Array

nagovind

Member
Dear All,

Please advise the code for storing the selected sheet names into an array
so that it is possible to loop through ONLY the selected sheets but one sheet at a time

Regards
Govind
 
This is working for me. Thanks

Dim ws As Worksheet
Dim SelectedSheets() As String
Dim n As Long, i As Long

n = 1
For Each ws In ActiveWindow.SelectedSheets
ReDim Preserve SelectedSheets(n)
SelectedSheets(n) = ws.Name
n = n + 1
Next

For i = 1 To UBound(SelectedSheets)
code...
Next
 
What about:

Code:
Sub StoreShtNamesinArray()

Dim ShtArr As Variant
ReDim ShtArr(Sheets.Count)

For i = 1 To Sheets.Count
  ShtArr(i) = Sheets(i).Name
Next
End Sub

Then you can apply whatever criteria you want to it
 
and if you want to apply criteria:

Code:
Sub StoreShtNamesinArray()

Dim ShtArr As Variant
ReDim ShtArr(0)
For i = 1 To Sheets.Count
  If Left(Sheets(i).Name, 4) = "List" Then 'Set criteria here
   ReDim Preserve ShtArr(UBound(ShtArr, 1) + 1)
  ShtArr(UBound(ShtArr, 1)) = Sheets(i).Name
  End If
Next
End Sub

ShtArr(1) to ShtArr(x) Will contain the filtered sheet names
ShtArr(0) will be blank
 
Back
Top