troubleshooting Question

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

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

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert

See if this solution works for you by signing up for a 7 day free trial.

Unlock 1 Answer and 9 Comments.

Try for 7 days”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.