Selected Answer
Malkal
In the revised macro below (and file), I've just added another loop (like yours) to add the quantities in Column D- changes are in bold. Other users please note that (at Malka's request in the Discussion below), this Total deliberately ignores the first entry in each "block" (this seems to run contrary to all quantity columns I've worked with!)
Private Sub CommandButton1_Click()
Dim lRow As Long
Dim lValue As Variant
Dim Ttl As Double, i As Long, n As Long
lRow = Worksheets("DETAILS").Cells(Rows.Count, 1).End(xlUp).Row
With Worksheets("DETAILS")
For i = lRow To 2 Step -1
If .Cells(i, 2).Value = UserForm1.ComboBox1.Value And .Cells(i, 3).Value = UserForm1.ComboBox2.Value And .Cells(i, 4).Value = UserForm1.ComboBox3.Value Then
lValue = .Cells(i, 5).Value - UserForm1.TextBox1.Value
UserForm1.TextBox2.Value = lValue
.Rows(i).Copy
.Rows(i + 1).EntireRow.Insert , xlFormatFromLeftOrAbove
.Cells(i + 1, 1).Value = Format(Date, "dd/mm/yyyy")
.Cells(i + 1, 5).Value = lValue
Application.CutCopyMode = False
'calculate Total BUT ignore first entry in each "block"
For n = i To 1 Step -1
If IsNumeric(.Cells(n, 5)) Then
'add from E to total
Ttl = Ttl + .Cells(n + 1, 5).Value
Else
'write total
.Cells(i + 2, 5).Value = Ttl
Exit For
End If
Next n
Exit For
End If
Next i
End With
End Sub
Note: I'm still nit sure about the number you add to the Qty column (when I put a QTY is the UserForm, your macro added the REMAINED value to the new row instead).
Hope this is what you want.