Wednesday, January 22, 2014

VBA - Loop through all elements of an Array

Simple code to loop through the values of an Array:


Sub LoopArray()
    MyArray = Array("January", "February", "March", "April", "May", _
        "June", "July", "August", "September", "October", _
        "November", "December")
    
    For x = LBound(MyArray) To UBound(MyArray)
        MsgBox ("On element " & x & " which has a value of " & MyArray(x))
    Next
End Sub

No comments:

Post a Comment