2-D数组的预期数组错误

时间:2014-07-22 14:05:57

标签: arrays string excel-vba multidimensional-array vba

我试图创建一个二维动态数组,但不断收到错误"预期数组"当涉及到ReDiming the bigArray时。关于为什么会发生这种情况的任何意见?此外,任何有关创建此2D阵列的帮助都将受到赞赏。

谢谢

Sub Button2_Click()


Dim i As Integer, j As Integer
Dim Lastrow As Long
Sheets("3").Activate
Lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
Sheets("4").Activate

Dim myArray As String
**Dim bigArray As String
ReDim bigArray(0 To 1, 0 To 1) As String**
j = 0


For i = 2 To Lastrow
    If Not IsEmpty(Sheets("3").Cells(i, 1).Value) Then
        myArray = Array(CStr(Sheets("3").Cells(i, 10).Value), CStr(Sheets("3").Cells(i, 20).Value))
        If UBound(myArr) > 1 Then
            ReDim Preserve bigArray(LBound(bigArray) To UBound(bigArray) + 1, 0 To 1) As String
        End If
        bigArray(UBound(bigArray), 0) = myArray(0)
        bigAray(UBound(bigArray), 1) = myArray(1)
    End If
Next i

End Sub

1 个答案:

答案 0 :(得分:1)

使用()

声明

Arrays in Excel

Dim bigArray() As String
ReDim bigArray(0 To 1, 0 To 1) As String