|
配列を使ったコード例。(色々な書き方があるので一例として)
Sub test2()
Dim lastRow As Long
Dim mysize As Long
Dim mat() As Variant
Dim v As Variant
Dim k As Long
Dim j As Long
Dim m As Long
Dim kk As Long
Dim t '経過時間計測用
t = Timer
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
'できあがりの表の行数
mysize = WorksheetFunction.Ceiling(lastRow / 3, 1)
'結果一時保持用配列の大きさを宣言
ReDim mat(1 To mysize, 1 To 9)
'元データを配列vに取り込む
v = Range("A1").CurrentRegion.Resize(mysize * 3, 3).Value
For k = 1 To mysize * 3 Step 3
kk = Int((k - 1) / 3) + 1
For j = 1 To 3
For m = 1 To 3
mat(kk, (j - 1) * 3 + m) = v(k + j - 1, m)
Next
Next
Next
'纏めて書込む
[E1].Resize(mysize, 9).Value = mat
Debug.Print "配列利用 "; Timer - t
End Sub
|
|