无法解决VBA阵列错误13类型不匹配

时间:2019-09-06 18:19:03

标签: excel vba

我正在尝试创建数组的子集。我在google上阅读其他文章,但我无法管理。我在这里做什么错了?

Dim startIndex As Long
startIndex = 13
Dim myArray As Variant
myArray = tbl.ListRows(x).Range

Dim sortArray As Variant
Dim y, yy As Long
y = 0
yy = 1
For y = startIndex To tbl.DataBodyRange.Columns.Count
    sortArray(yy) = myArray(1, y)
    yy = yy + 1
Next

sortArray(yy)上说类型不匹配,但我看不到。
sortArray(yy)myArray(1,y)中的整数不匹配吗?

1 个答案:

答案 0 :(得分:0)

谢谢@Damian。

    Dim sortArray As Variant
    Dim sortArrayDim As Long
    sortArrayDim = tbl.DataBodyRange.Columns.Count - startIndex
    ReDim sortArray(sortArrayDim)
    Dim y, yy As Long
    y = 0
    yy = 0
    For y = startIndex To tbl.DataBodyRange.Columns.Count
        sortArray(yy) = myArray(1, y)
        yy = yy + 1
    Next