Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 重新定义二维数组_Arrays_Excel_Excel 2013_Vba - Fatal编程技术网

Arrays 重新定义二维数组

Arrays 重新定义二维数组,arrays,excel,excel-2013,vba,Arrays,Excel,Excel 2013,Vba,我正在努力重新定义数组。我已简化了我的代码,请参见以下内容: Sub Knop1_Klikken() 'all the cells are defined in an array Dim col, i As Integer, defrow As Long Dim notAct(1 To 20, 1 To 43) As Integer For col = 2 To 4 For row = 1 To 20 notAct(row, kol) = 0 'setting 0 no

我正在努力重新定义数组。我已简化了我的代码,请参见以下内容:

Sub Knop1_Klikken()
'all the cells are defined in an array
Dim col, i As Integer, defrow As Long
Dim notAct(1 To 20, 1 To 43) As Integer

For col = 2 To 4
    For row = 1 To 20
        notAct(row, kol) = 0 'setting 0 not required after Dim
        Cells(row, kol).Value = notAct(row, kol)
    Next row
Next col
'a loop with a if-statement to see if a specifica
For x = 1 To 100
    If notAct(2, 2) = 0 Then
             i = i + 1
             If i = 10 Then
                notAct(2, 2) = 1
             End If
    End If
Next x

End Sub
问题是我想
redim
数组。我在for循环
next x

MsgBox notAct(2, 2) 'it returns a 0
ReDim notAct(2, 2)
MsgBox notAct(2, 2) 'it returns a 0

vba不欣赏ReDim注释(2,2)。有没有办法让redim在2d阵列中工作。我想在notAct(2,2)得到1时返回该值。

您需要先调暗不带维度的数组:

Dim notAct() as Integer
您可以重新确定其尺寸:

Redim notAct(1 to 20, 1 to 43) as Integer
请注意,重新确定阵列的尺寸将导致其丢失当前存储的所有数据。要保留数据,需要使用preserve关键字:

Redim Preserve notAct(1 to 20, 1 to 2) as Integer
请注意,使用“保留”关键字时,只能更改最后一个维度的边界