title: Can't pass string into array function : subscript out of range
body: <p>I'm trying to imitate copying multiple sheets to a new workbook and this is fine if I literally use the sheet names in the array function.</p>
  
  <p>However if I try to pass a string variable into the array I get a subscript out of range error. </p>
  
  <p>The line of concern is:</p>
  
  <pre><code>Wb.Sheets(Array(SheetsArray)).Copy After:=RegionWb.Sheets(RegionWb.Sheets.count)
  </code></pre>
  
  <p>Please see my code below :</p>
  
  <pre><code>Sub CreateFiles()
      Application.ScreenUpdating = False
      Dim LastRow As Long
      Dim WKC As String: WKC = Replace(DateValue(DateAdd("ww", -1, Now() - (Weekday(Now(), vbMonday) - 1))), "/", ".")
      Dim FilePath As String: FilePath = "Z:\MI\Krishn\Retail"
      Dim BuyerLastRow As Long
      Dim Wb As Workbook: Set Wb = ActiveWorkbook
      Dim RegionWb As Workbook
      Dim RegionCount As Integer
      Dim RegionCounter As Integer
      Dim SheetsArray As String
          With BuyerList
              LastRow = .Range("G1048576").End(xlUp).Row
              BuyerLastRow = .Range("A1048576").End(xlUp).Row
              'Create WKC Dir
  
              If Dir(FilePath &amp; "\" &amp; WKC, vbDirectory) = "" Then
                  MkDir FilePath &amp; "\" &amp; WKC
              End If
  
              'Create Create Files
              If CountFiles(FilePath &amp; "\" &amp; WKC) = 0 Then
                  For i = 2 To LastRow
                      RegionCounter = 0
                      SheetsArray = ""
  '                    Set RegionWb = Workbooks.Add
  '                    'wb.SaveAs FilePath &amp; "\" &amp; WKC &amp; "\" &amp; .Cells(i, 7).Value
  '                    RegionWb.SaveAs FilePath &amp; "\" &amp; WKC &amp; "\" &amp; "WKC " &amp; WKC &amp; " - " &amp; .Cells(i, 7).Value &amp; ".xlsb", 50
  
                          For j = 2 To BuyerLastRow
                              RegionCount = Application.WorksheetFunction.CountIf(.Range("C:C"), .Cells(i, 7).Value)
                              If .Cells(i, 7).Value = .Cells(j, 3).Value Then
                                  SheetsArray = SheetsArray &amp; """" &amp; .Cells(j, 2).Value &amp; ""","
                                  RegionCounter = RegionCounter + 1
                                  If RegionCounter = RegionCount Then
                                      Debug.Print Left(SheetsArray, Len(SheetsArray) - 1)
                                      Set RegionWb = Workbooks.Add
                                      RegionWb.SaveAs FilePath &amp; "\" &amp; WKC &amp; "\" &amp; "WKC " &amp; WKC &amp; " - " &amp; .Cells(i, 7).Value &amp; ".xlsb", 50
                                      'Wb.Sheets(Array(Left(SheetsArray, Len(SheetsArray) - 1))).Copy After:=RegionWb.Sheets(RegionWb.Sheets.count)
                                      SheetsArray = Left(SheetsArray, Len(SheetsArray) - 1)
                                      Wb.Sheets(Array(SheetsArray)).Copy After:=RegionWb.Sheets(RegionWb.Sheets.count)
                                      'Wb.Sheets(Array()).Copy After:=RegionWb.Sheets(RegionWb.Sheets.count)
                                      RegionWb.Save
                                      RegionWb.Close
                                      Exit For
                                  End If
  '                                Wb.Sheets(Wb.Sheets("Buyer list").Range(Cells(j, 2).Address).Value).Copy After:=RegionWb.Sheets(RegionWb.Sheets.count)
                              End If
                          Next j
  '
  '
  
                  Next i
              End If
  
  
          End With
      Application.ScreenUpdating = True
  End Sub
  </code></pre>