Well this is the problem using binaries to calculate numbers. You do get these differeces occasionaly and -1.776E-15
is not that much after all its only -0.0000000000000001776
That you don't see this when you run the "problem" order is because the way the macro is set up i.e. there is no TAX-A column in this order so macro adds a "TAX-A" column but skips setting up a formula for "Discount"
If you do wish to have a discount callculated every time just change the lines:
Columns("J:J").Insert Shift:=xlToRight
Range("J1") = "Discount"
If Range("K1").Value <> "Tax-A" Then
Columns("K:K").Insert Shift:=xlToRight
Range("K1") = "Tax-A"
Else
Range("J2").Formula = "=IF(SUM(C2-(D2+I2+K2))=0,"""",IF(SUM(C2-(D2+I2+K2))<0,SUM(C2-(D2+I2+K2)),""""))"
Range("J2").Copy
Range("J3:J" & i).PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False
End If
to
Columns("J:J").Insert Shift:=xlToRight
Range("J1") = "Discount"
If Range("K1").Value <> "Tax-A" Then
Columns("K:K").Insert Shift:=xlToRight
Range("K1") = "Tax-A"
End If
Range("J2").Formula = "=IF(SUM(C2-(D2+I2+K2))=0,"""",IF(SUM(C2-(D2+I2+K2))<0,SUM(C2-(D2+I2+K2)),""""))"
Range("J2").Copy
Range("J3:J" & i).PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False
Getting rid of -1.7E-15 is possible by setting a number format on column J
Range("J2:J" & i).NumberFormate = "0.00"
Or one could delete the formula in those cases where value was less than say 0,0000
Alf
Bookmarks