Sometimes you just need a quick and dirty way to loop through a predefined list of items. For these situations, I like to combine the Array() function with a For Each loop.
Sub TestForEachArray() Dim DayName As Variant For Each DayName In Array("Mon", "Tue", "Wed", "Thu", "Fri") Debug.Print DayName Next DayName End Sub
To make this work, the iterator variable must be declared as a Variant. You lose the benefits of type safety with Variants, which is why I labeled this a "quick and dirty" solution.
The order the items appear in the call to the Array() function is the same order they will be accessed within the loop.
You can stuff just about anything into a Variant, including custom object instances. Also, the Array() function will gladly accept a mix of Variants with different underlying data types all in the same function call. So, while I can't think of any reason you would want to do this, at least now you know you can do this: