Selected Answer
Dividenar
The overflow error arises since your code says:
If txtMarkup.Value = "" Then txtMarkup.Value = 0
so your following line:
txtNegAmt.Value = (CDbl(txtTOTALcst.Value) / CDbl(txtMarkup.Value) * 100
is a "divide by zero" calculation which overflows the maximum value of a Double variable or any variable in fact, since it's infinity!
I also think your logic is wrong in that the first line:
'If Not txtTOTALcst.Value = "" Then txtTOTALcst.Value = 0
since it always sets txtTOTALcst to zero (and furthermore 0/0 calculations are indeterminate!).
In the attached revised file, I've:
- commented out/ replaced that line and
- corrected your Negotiation $ calculation and
- rounded up the resultant Negotiaton value to 2 decimal places for currency (though you may need first to change the end of that line from the form "###.00" to "###,00" for your locale). You might want to do similar for total cost.
See changes in bold:
Private Sub txtTOTALcst_Change()
'If Not txtTOTALcst.Value = "" Then txtTOTALcst.Value = 0
If txtTOTALcst.Value = "" Then txtTOTALcst.Value = 0
' make this a default value
If txtMarkup.Value = "" Then txtMarkup.Value = 10
'txtNegAmt.Value = (CDbl(txtTOTALcst.Value) / CDbl(txtMarkup.Value) * 100)
txtNegAmt.Value = (CDbl(txtTOTALcst.Value) * CDbl(txtMarkup.Value)) / 100
'format that to 2 decimal places (change decimal marker if needed)
txtNegAmt.Value = Format(WorksheetFunction.RoundUp(txtNegAmt.Value, 2), "###.00")
End Sub
Private Sub txtMarkup_Change()
'If Not txtTOTALcst.Value = "" Then txtTOTALcst.Value = 0
If txtTOTALcst.Value = "" Then txtTOTALcst.Value = 0
' make this a default value
If txtMarkup.Value = "" Then txtMarkup.Value = 10
txtNegAmt.Value = (CDbl(txtTOTALcst.Value) * CDbl(txtMarkup.Value)) / 100
'format that to 2 decimal places (change decimal marker if needed)
txtNegAmt.Value = Format(WorksheetFunction.RoundUp(txtNegAmt.Value, 2), "###.00")
sh.Cells(iRow + 1, 11) = txtMarkup.Value
End Sub
Alternatively, you might use MROUND to round to the nearest 5 cents (say, =0.05), using:
txtNegAmt.Value = Format(WorksheetFunction.MRound(txtNegAmt.Value, 0.05), "###.00")
(again adjusting the decimal separator as necessary).
Hope this works for you (now you can easily add cost and negotiation value to get Selling Price).