Q:

Declare an array using a for loop vba

I want to make an array of the values: w1, w2, w3, y1, y2, y3 ... etc, but got an error in my code:
sub array()

Dim titles() as string

For i = 1 to 3

titles(i + 0) = "w" + i
titles (i + 3) = "y" + i
titles (i + 6) = "x" + 1

'...

Next i

End sub

A:

You were quite close:
Sub arrray()

    Dim titles(1 To 9) As String
    Dim i As Long

    For i = 1 To 3
        titles(i + 0) = "w" & i
        titles(i + 3) = "y" & i
        titles(i + 6) = "x" & i
    Next i

    For i = 1 To 9
        MsgBox titles(i)
    Next i
End Sub

