VBA --
'--------------------------------------------------------
Sub test_ReDim()
'宣言
Dim arr() As String
ReDim arr(0)
'代入
ReDim Preserve arr(1)
arr(1) = "東京"
ReDim Preserve arr(2)
arr(2) = "大阪"
'追加
ReDim Preserve arr(3)
arr(3) = "名古屋"
'全参照
For i = UBound(arr) To LBound(arr) Step -1
Debug.Print arr(i)
Next i
End Sub
'--------------------------------------------------------
'Excelにて レンジをコピーして、貼り付けする
Dim arr() As Range
x = 0
For i = 1 To 10
'配列の初期化
ReDim arr(0)
'動的配列の再割り当て
ReDim Preserve arr(x)
'レンジを格納
Set arr(x) = Range(Cells(i, 2), Cells(i, 10))
'代入
Range(Cells(i, 20), Cells(i, 30)).Value = arr(x).Value
x = x + 1
Next i
For i = LBound(arr) To UBound(arr)
Debug.Print arr(i)
Next i
|