添付画像のようにNo.4に複数の別値が存在してそれぞれ一行にしたいという場合です。
4と1と5を一行にしています。5はもともと一行なのでそのまま。
Sub Test3()
Dim i As Long, LastRow As Long, LastRow2 As Long
Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
AutoFilterMode = False
LastRow2 = Cells(Rows.Count, "G").End(xlUp).Row + 1
If WorksheetFunction.CountIf(Range(Cells(i, "D"), Cells(LastRow, "D")), Cells(i, "D")) >= 2 And _
WorksheetFunction.CountIf(Range(Cells(2, "D"), Cells(i, "D")), Cells(i, "D")) = 1 Then
Range(Cells(1, "A"), Cells(LastRow, "E")).AutoFilter Field:=4, Criteria1:=Cells(i, "D").Value
Cells(LastRow2, "G").Value = Cells(i, "A").Value
Cells(LastRow2, "H").Value = WorksheetFunction.Subtotal(5, Range(Cells(2, "B"), Cells(LastRow, "B")))
Cells(LastRow2, "I").Value = WorksheetFunction.Subtotal(4, Range(Cells(2, "C"), Cells(LastRow, "C")))
Cells(LastRow2, "J").Value = Cells(i, "E").Value
ElseIf WorksheetFunction.CountIf(Range(Cells(2, "D"), Cells(LastRow, "D")), Cells(i, "D")) = 1 Then
Cells(LastRow2, "G").Value = Cells(i, "A").Value
Cells(LastRow2, "H").Value = Cells(i, "B").Value
Cells(LastRow2, "I").Value = Cells(i, "C").Value
Cells(LastRow2, "J").Value = Cells(i, "E").Value
End If
Next
Application.ScreenUpdating = True
End Sub