Loop Through Worksheets
VBA

Loop Through in Worksheets, Sheets & Chart in VBA

In this article, we have explained the difference between Chart Sheet and Worksheet in Excel. We have also explained how to loop through the Charts, Sheets and Worksheets.

The difference between Chart Sheets and Worksheets

A Worksheets are Sheets, but not all Sheets are Worksheets.  There are 2 types of Sheets:

Worksheet: The sheet with the gridlines and cells.

Worksheet
Worksheet

Chart Sheet: The sheet which contains a single chart.

Chart Sheet
Chart Sheet

Loop through Worksheets –

Sub LoopthroughinWorksheets()

Dim i As Integer
Dim wsh As Worksheet

For Each wsh In ThisWorkbook.Worksheets
MsgBox wsh.Name
Next

End Sub

Loop through Sheets –

Sub LoopthroughinSheets()

Dim i As Integer


For i = 1 To ThisWorkbook.Sheets.Count
MsgBox ThisWorkbook.Sheets(i).Name

Next i

End Sub

Loop through Chart Sheets–

Sub LoopThroughinChartsheets()

Dim cht As Chart

For Each cht In ThisWorkbook.Charts

MsgBox cht.Name
Next


End Sub

 

Click here to download practice file-

Watch the step by step video tutorial:

PK
My Name is PK. I am founder of PK-AnExcelExpert.com. I am a Microsoft Certified Professional. I have more than 10 years of experience in Data Visualization, Excel Automation and dashboard creation. Excel is my passion and I like to do always something innovative in Excel and share it with other people.
https://www.pk-anexcelexpert.com