Option Base 1
Sub test()
Dim count As Integer
' one-dimensional array to range
Dim arr1(10) As Variant
count = 1
For i = LBound(arr1, 1) To UBound(arr1, 1)
arr1(i) = count
Debug.Print count
count = count + 1
Next
[a12].Resize(1, UBound(arr1)) = arr1 'write to one row
[a15].Resize(UBound(arr1, 1), 1) = WorksheetFunction.Transpose(arr1) 'write to one column
'two-dimensional array to range
Dim arr(9, 10) As Variant
count = 1
For i = LBound(arr, 1) To UBound(arr, 1)
For j = LBound(arr, 2) To UBound(arr, 2)
arr(i, j) = count
count = count + 1
Next
Next
[a1].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
'range to array
Dim a, temp
a = Range("a1:j9")
For i = LBound(a, 1) To UBound(a, 1)
temp = ""
For j = LBound(a, 2) To UBound(a, 2)
temp = temp & " " & a(i, j)
Next
Debug.Print temp
Next
End Sub
array range
猜你喜欢
转载自tangleilei.iteye.com/blog/2308432
今日推荐
周排行