从多维数组中提取

时间:2014-08-04 22:48:40

标签: vba excel-vba excel

我有一个显示dat

的数组Type = Variant/Variant(0 to 500, 0 to 0, 0 to 1)

有一个日期的“列”:

dat(0, 0, 0) = #1/1/2013#
dat(1, 0, 0) = #1/2/2013#

我想提取这组日期。我试过了:

Dim dat As Variant
Dim dt As Variant
'stuff gets dat in the format described above
dt = Application.Index(dat, 0, 1, 1)

不幸的是,这给了我一个错误13类型不匹配。我做错了什么?

1 个答案:

答案 0 :(得分:1)

使用循环

Sub dural()
    Dim dat(0 To 500, 0 To 1, 0 To 1) As Variant

    dat(0, 0, 0) = #1/1/2013#
    dat(1, 0, 0) = #1/2/2013#

    Dim dt(0 To 500) As Variant

    For i = 0 To 500
        dt(i) = dat(i, 0, 0)
    Next i

End Sub