troubleshooting Question

Excel 201 rounding creating a problem with my macro

Avatar of William C Johnson
William C JohnsonFlag for United States of America asked on
Microsoft ExcelMicrosoft Office
9 Comments1 Solution81 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

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.

-Mike Kapnisakis, Warner Bros