I am trying to get the OilTotal cell to change based upon the entry in the OilQuantity cell. I’m sure this has to do with rounding. Can someone help debug my macro or make it easier to read/understand? See attached file.

Item Qty Unit Price Total

Cake Mix 27 $2.00 $54.00

Oil (48 oz) 72.00000009 $2.00 $2.00

Sub Recalculate()

'

' Recalculate Macro

'

If OilQuantity = 2.66666667 Then OilTotal.Formula = "=OilUnitPrice * 1"

If OilQuantity = 5.33333334 Then OilTotal.Formula = "=OilUnitPrice * 1"

If OilQuantity = 8.00000001 Then OilTotal.Formula = "=OilUnitPrice * 1"

If OilQuantity = 10.66666668 Then OilTotal.Formula = "=OilUnitPrice * 1"

If OilQuantity = 13.33333335 Then OilTotal.Formula = "=OilUnitPrice * 1"

If OilQuantity = 16.00000002 Then OilTotal.Formula = "=OilUnitPrice * 1"

If OilQuantity = 18.66666669 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 21.33333336 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 24.00000003 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 26.6666667 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 29.33333337 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 32.00000004 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 34.66666671 Then OilTotal.Formula = "=OilUnitPrice * 2"

If OilQuantity = 37.33333338 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 40.00000005 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 42.66666672 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 45.33333339 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 48.00000006 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 50.66666673 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 53.3333334 Then OilTotal.Formula = "=OilUnitPrice * 3"

If OilQuantity = 56.00000007 Then OilTotal.Formula = "=OilUnitPrice * 4"

If OilQuantity = 58.66666674 Then OilTotal.Formula = "=OilUnitPrice * 4"

If OilQuantity = 61.33333341 Then OilTotal.Formula = "=OilUnitPrice * 4"

If OilQuantity = 64.00000008 Then OilTotal.Formula = "=OilUnitPrice * 4"

If OilQuantity = 66.66666675 Then OilTotal.Formula = "=OilUnitPrice * 4"

If OilQuantity = 69.33333342 Then OilTotal.Formula = "=OilUnitPrice * 4"

If OilQuantity > 72.00000009 Then OilTotal.Formula = "=OilUnitPrice * 5"

End Sub

Test.xltm
## Premium Content

You need an Expert Office subscription to comment.Start Free Trial