| 
    
     |  | ▼ゆうか さん: 
 上で質問したように、表の各ブロックごとに、どのような書式設定がお好みなのかはわからないので
 「適当」に。
 
 ブロックごとに分けてあるので、あとはいかようにでも、直してくださいね。
 
 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")
 
 '  Application.ScreenUpdating = False
 
 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)"
 
 '============ 罫線他の書式設定 開始
 
 .Cells.Borders.LineStyle = xlNone 'まず、すでにひかれている罫線があればそれを削除
 
 '1行目 タイトル行 ★これはあらかじめ書式設定しておけば、コード処理は不要
 With .Range("A1:F1")
 .HorizontalAlignment = xlCenter
 .VerticalAlignment = xlCenter
 End With
 '合計行
 With .Range("A" & dic.Count + 2)
 .Resize(, 5).HorizontalAlignment = xlCenterAcrossSelection '好みではなかったら xlCenterに。
 .Offset(, 5).HorizontalAlignment = xlCenter
 .Resize(, 6).VerticalAlignment = xlCenter
 End With
 'データ領域
 With .Range("A2", .Range("F" & dic.Count + 1))
 .HorizontalAlignment = xlCenter
 .VerticalAlignment = xlCenter
 End With
 '罫線
 With .Range("A1").CurrentRegion.Borders
 .LineStyle = xlContinuous
 .Weight = xlThin
 End With
 
 .Columns("A:F").EntireColumn.AutoFit '★これは、あらかじめ書式設定しておけばコード処理は不要
 
 '============ 罫線他の書式設定 終了
 .Select
 End With
 
 Application.ScreenUpdating = True
 
 Set dic = Nothing
 MsgBox "合計処理が完了しました"
 
 End Sub
 
 |  |