For Each Function, to loop through specifically named worksheets
excel, for-loop, foreach, vba
Solution
Ah, Tim beat me... my answer is slightly different however...
Sub LoopThroughSheets()
Dim Months As Variant
Dim Month As Variant
Months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", _
"Aug", "Sep", "Oct", "Nov", "Dec")
For Each Month In Months
'Code goes here.
Next Month
End Sub
Problem
I'm trying to figure out the right way to code a macro that goes through 12 worksheets with specific names (Jan,Feb,...,Dec). I thought maybe `for each` will be a good choice so I tried the following: ``` dim crntSht as worksheet set crntsht=("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") for each crntsht in worksheets . . . end for ``` This did not work since I defined `crntsht` in the wrong manner. Can anyone suggest the best way to loop through all 12 sheets once each, and skip all other sheets in the same workbook?