Home>Blogs>VBA>Loop Through in Worksheets, Sheets & Chart in VBA
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 Loop Through in 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 grid-lines and cells.

Loop Through in Worksheets

Loop Through in Worksheets
Loop Through in Worksheets

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:

 

Visit our YouTube channel to learn step-by-step video tutorials

Youtube.com/@PKAnExcelExpert

 

PK
Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!
https://www.pk-anexcelexpert.com