使用for循环vba声明一个数组

时间:2016-03-25 12:46:23

标签: arrays vba excel-vba loops for-loop

我想创建一个值数组:w1,w2,w3,y1,y2,y3 ......等,但在我的代码中出错:

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

1 个答案:

答案 0 :(得分:1)

你很亲密:

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