Option Explicit

Sub test()
    Dim r As Range
    Dim v
    Dim i As Long
    
    Set r = Range("k1", Range("k1").End(xlDown)).Resize(, 18)
    
    v = r.Value
    
    For i = 1 To UBound(v)
        If v(i, 5) = "Sell" Then v(i, 18) = v(i, 18) * -1
    Next
    
    r.Value = v
    
    r.Rows(1).Insert xlDown
    Set r = Range("k1").Resize(i, 18)
    Application.DisplayAlerts = False
    r.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(18), SummaryBelowData:=True
    Application.DisplayAlerts = True
    r.Rows(1).Delete xlUp
        
End Sub