-
StackOverflow 文档
-
excel-vba 教程
-
数组
-
动态数组数组声明调整大小
Sub Array_clarity()
Dim arr() As Variant 'creates an empty array
Dim x As Long
Dim y As Long
x = Range("A1", Range("A1").End(xlDown)).Cells.Count
y = Range("A1", Range("A1").End(xlToRight)).Cells.Count
ReDim arr(0 To x, 0 To y) 'fixing the size of the array
For x = LBound(arr, 1) To UBound(arr, 1)
For y = LBound(arr, 2) To UBound(arr, 2)
arr(x, y) = Range("A1").Offset(x, y) 'storing the value of Range("A1:E10") from activesheet in x and y variables
Next
Next
'Put it on the same sheet according to the declaration:
Range("A14").Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
End Sub