title: Looped charts and worksheets as sheets unsuccessfully. Exactly what caused the errors?
body: <p>I tried to loop charts and sheets as variants.</p>
  
  <pre><code>Sub ShowSheets(vSheets() As Variant)
  
      Dim i As Long
      For i = LBound(vSheets, 1) To UBound(vSheets, 1)
          Dim wks As Variant
          Set wks = ThisWorkbook.Sheets(vSheets(i, 1))
          wks.Visible = xlSheetVisible
      Next i
  
  End Sub
  </code></pre>
  
  <p><code>vSheets()</code> holds the names of the following sheets and charts:</p>
  
  <pre><code>SheetName1
  SheetName2
  ChartName1
  SheetName3
  SheetName4
  </code></pre>
  
  <p>The subrutine was unsuccessful. I got an error on row <code>wks.Visible = xlSheetVisible</code> when <code>wks</code> was the worksheet named <code>SheetName3</code>.</p>
  
  <p>The error was:</p>
  
  <pre><code>Run-time error '-2147417848 (80010108)':
  
  Method 'Visible' of object '_Worksheet' failed
  </code></pre>
  
  <p>Why did I get an error on that specific line?</p>
  
  <p>The following subroutine was also unsuccessful:</p>
  
  <pre><code>Sub ShowSheets(vSheets() As Variant)
  
      Dim i As Long
      For i = LBound(vSheets, 1) To UBound(vSheets, 1)
          ThisWorkbook.Sheets(vSheets(i, 1)).Visible = xlSheetVisible
      Next i
  
  End Sub
  </code></pre>
  
  <p>I got an error on in the same situation. On the row <code>ThisWorkbook.Sheets(vSheets(i, 1)).Visible = xlSheetVisible</code>, when <code>ThisWorkbook.Sheets(vSheets(i, 1)).Name</code> was <code>SheetName3</code>. I don't understand why the subroutine above did not work.</p>
  
  <p>I figure that I should have gotten an error when wks was the chart. That I would have understood. I don't understand why I got the error when wks was the first worksheet after the chart.</p>
  
  <p>The following subroutine, works, but I still can't figure out why I got the error where I got it in the subroutines above:</p>
  
  <p><strong>What caused the errors in the first two subrutines? Why did I get errors when the worksheet was <code>SheetName3</code>?</strong></p>
  
  <pre><code>Sub ShowSheets(vSheets() As Variant)
  
      Dim i As Long
  
      For i = LBound(vSheets, 1) To UBound(vSheets, 1)
          If TypeName(ThisWorkbook.Sheets(vSheets(i, 1))) = "Worksheet" Then
              ThisWorkbook.WorkSheets(vSheets(i, 1)).Visible = xlSheetVisible
          End If
      Next i
  
      For i = LBound(vSheets, 1) To UBound(vSheets, 1)
          Debug.Print (TypeName(ThisWorkbook.Sheets(vSheets(i, 1))))
          If TypeName(ThisWorkbook.Sheets(vSheets(i, 1))) = "Chart" Then
              ThisWorkbook.Charts(vSheets(i, 1)).Visible = xlSheetVisible
          End If
      Next i
  
  End Sub
  </code></pre>