我有這樣的代碼,將填充數組粘貼VBA陣列
Sub rangearray()
Dim arr() As Variant
Dim Rng As Range
Dim myCell As Range
Dim i As Integer
Set Rng = ActiveSheet.Range("G10:G14")
For Each myCell In Rng
ReDim Preserve arr(i)
arr(i) = myCell
i = i + 1
Next myCell
ActiveSheet.Range("H10:H14") = arr()
End Sub
在這裏你可以看到,在監視窗口中值是什麼一直在
除了加載,當我將數組添加回工作簿時,它僅粘貼數組的第一個元素。
是否有可能將整個陣列工作表粘貼不通過陣列,具有循環?
UPDATE考慮看看從Sorceri鏈接後我已經修改了代碼使用.Transpose功能,所以我修改的代碼現在看起來是這樣:
Sub rangearray()
Dim arr() As Variant
Dim Rng As Range
Dim myCell As Range
Dim i As Integer
Set Rng = ActiveSheet.Range("A1:A5")
For Each myCell In Rng
ReDim Preserve arr(i)
arr(i) = myCell
i = i + 1
Next myCell
ActiveSheet.Range("B1:B5") = WorksheetFunction.Transpose(arr)
End Sub
爲什麼你需要一個這樣的數組?請參閱[本](http://stackoverflow.com/questions/19277994/error-13-when-pasting-from-another-workbook/19280614#19280614) –
因爲我想從一個數組粘貼,而不是從另一個範圍 – spences10
但是,那不是你在做什麼? '範圍(「G10:G14」) - >範圍(「H10:H14」)' –