Dear Reader,

In this article, I am going to write a very small trick about Excel Macro. In Excel Macro, you might have come across the situation where you need to Traverse all the Sheets of any Workbook one by one. You might have seen the below two methods to do so. As part of this article we will discuss what exactly the difference is between both the below methods:


Sub TraverseWorkSheet()
  Dim ws As Worksheet
  For Each Worksheet In Worksheets
   MsgBox (Worksheet.Name)
End Sub


Sub TraverseSheet()
  For Each Sheet In Sheets
   MsgBox (Sheet.Name)
End Sub


If you are using the KeyWord Sheet in Sheets then it will traverse all the WorkSheets of that Workbook, including Charts, Macro Sheet, International Macro Sheets etc..

See Example 2, above

In other hand if you use Keyword WorkSheet in WorkSheets then it will traverse only the WorkSheets. It will ignore all the Other Sheets like Charts, Macro Sheet, International Macro Sheets etc.

See Example 1, above


Join over 10, 000+ Excel VBA Enthusiasts & get this FREE e-Book Now!