|
▼ゆうか さん:
ごめんなさい。コードを1行追加しました。
Sub Sample()
Dim v As Variant
Dim z As Long
Dim i As Long
Dim k As Long
Dim dic As Object
Dim dKey As String
Dim c As Range
Dim w As Variant
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("集計")
z = .Range("A1").CurrentRegion.Rows.Count - 1
ReDim v(1 To z, 1 To 6)
For Each c In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
dKey = Join(WorksheetFunction.Index(c.Resize(, 4).Value, 1, 0), vbTab)
If Not dic.exists(dKey) Then
dic(dKey) = dic.Count + 1
i = dic(dKey)
v(i, 1) = c.Value
v(i, 2) = c.Offset(, 1).Value
v(i, 3) = c.Offset(, 2).Value
v(i, 4) = c.Offset(, 3).Value
End If
i = dic(dKey)
v(i, 5) = v(i, 5) + c.Offset(, 4).Value
v(i, 6) = v(i, 6) + c.Offset(, 5).Value
Next
End With
With Sheets("集計合計")
.Cells.ClearContents
.Range("A1:F1").Value = Sheets("集計").Range("A1:F1").Value
.Range("A2").Resize(dic.Count, 6).Value = v
.Rows(2).Resize(dic.Count).Sort key1:=.Range("A2"), Order1:=xlAscending, Header:=xlNo
.Range("A" & dic.Count + 2).Value = "合計"
.Range("F" & dic.Count + 2).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
.Select
End With
Set dic = Nothing
MsgBox "合計処理が完了しました"
End Sub
|
|