Difference between Sheets and Worksheets in Excel Macro
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) Next End Sub
Sub TraverseSheet() For Each Sheet In Sheets MsgBox (Sheet.Name) Next 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
My name is Vishwamitra Mishra. Friends Call me Vishwa. This blog is authored by me. I am an Excel Geek. Well, this blog talks a lot about my passion in Excels & Macros so I’ll not talk about it :) I am very much passionate about traveling & quite recently discovered that I am a good photographer too..:P
AND GET A FREE!
E-BOOK FOR EXCEL VBA BEGINNERS
DON'T MISS ANY NEW ARTICLE !
Get your FREE! E-Book & Have Every New Article Delivered Straight To Your Email-Box