本文为《别怕,Excel VBA其实很简单(第3版)》随书问题参考答案
下面是给二维数组赋值,并将其写入单元格区域的参考过程:
Sub 使用二维数组存储数据()
Dim arr(1 To 11, 1 To 6) '存入数组的数据类型不确定,所以数组不指定类型
Dim Ir As Byte, Ic As Byte
'将数据逐个存入数组
For Ir = 1 To 11
For Ic = 1 To 6
arr(Ir, Ic) = Worksheets(1).Cells(Ir, Ic).Value
Next Ic
Next Ir
'将数组中数据逐个写入单元格
For Ir = 1 To 11
For Ic = 1 To 6
Worksheets(2).Cells(Ir, Ic).Value = arr(Ir, Ic)
Next Ic
Next Ir
End Sub