|
▼たく さん:
集計用に配列は別に用意し、
dicにはインデックスを登録でももよいです。
理解しやすいほうをお使いください。
Sub 日時集計2()
Dim dKey As String
Dim c As Range
Dim dic As Object
Dim v()
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("ソート")
For Each c In .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
dKey = c.Value & vbTab & c.Offset(, 3).Value
If Not dic.exists(dKey) Then
n = dic.Count + 1
dic(dKey) = n
ReDim Preserve v(1 To 5, 1 To n)
v(1, n) = c.Value
v(2, n) = c.Offset(, 3).Value
v(3, n) = c.Offset(, 4).Value
End If
n = dic(dKey)
v(4, n) = v(4, n) + c.Offset(, 7).Value
v(5, n) = v(5, n) + c.Offset(, 9).Value
Next
End With
With Worsheets.Add
.Name = "日時集計"
.Range("A1").Resize(UBound(v, 2), 5).Value = _
WorksheetFunction.Transpose(v)
.Select
End With
Set dic = Nothing
End Sub
|
|