狐的传说
假设您的电子表格看起来像这样有一种非常简单的方法可以将其粘贴在2D阵列中Dim arr as Variantarr = Range("B6:H14").Value将此数组打印回电子表格的最简单方法Sub PrintVariantArr()
Dim arr As Variant
arr = Range("B6:H14")
Range("B16").Resize(UBound(arr, 1), UBound(arr, 2)) = arrEnd Sub或者您可以迭代/循环数组Sub RangeToArray()
Dim arr As Variant
arr = Range("B6:H14").Value Dim r As Long, c As Long
r = 16
c = 2
Dim i, j For i = LBound(arr, 1) To UBound(arr, 1)
For j = LBound(arr, 2) To UBound(arr, 2)
Cells(r, c) = arr(i, j)
c = c + 1
Next j
c = 2
r = r + 1
Next iEnd Sub并且您的阵列打印回电子表格