Problem With <>

Sharmastic

New Member
Joined
Dec 17, 2012
Messages
3
Hi,
i'm having a problem with the <> (not Equal) giving the wrong answer,

i have 2 values that are both identical in every way i can find except the <> says they are different,

in excel watch both values are displayed as Type Variant/Double and both = 0.47 and yet the following code says they are different,


If Application.RoundUp(Cells(RowID, "Q"), 2) <> Application.RoundUp((Cells(RowID, "G") * 1.1 * (1 + (Cells(RowID, "E") / 100))), 2) Then

it basically checks that the price is correct by using the Cost (Cells(RowID, "G"))) adding 10% then adding any Vat ((Cells(RowID, "E")) which matches the value in Cells(RowID, "Q"),

They both display as identical in the Watch window and the same Type (Variant/Double) and yet the Macro is adamant they are both different?????

the if statement returns True, if i change the <> to = it comes up as false. is there anything i'm missing that i should check to try and find a differance??

it does this with about 7000 out of 30000 checks and i carn't figure out why.

Many thanks in advance for any help,
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The code works for me with manual entry of the values.

You could set a variable to each expression and look at those in the Locals window, and subtract them to see the difference.
 
Upvote 0
The code works for me with manual entry of the values.

You could set a variable to each expression and look at those in the Locals window, and subtract them to see the difference.


Many thanks SHG,
turns out when i subtract 0.47 from 0.47 i get -5.55111512312578E-17 so im guessing its skipping the rounding up in the equations,
ive solved it by adding application.round to the answer which rounds to 0 dec points making it = 0 so it now works, bit of a farse though,
so now have

Code:
If Application.Round(Cells(RowID, "Q") - (Cells(RowID, "G") * 1.1 * (1 + (Cells(RowID, "E") / 100))), 0) = 0 Then

Still dont get why the previous doesnt work on mine (Using Microsoft Office Home and Business 2010) but problem solved.

not 100% exact but close enough for what i need it to do so thanks again shg.
 
Upvote 0
As a matter of practice, you should always compare floating-point numbers with an epsilon to accommodate numerical precision issues. Or use the Currency data type in VBA, which is a scaled integer.
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,602
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top