strange comparison operator result in VBA, two equal double type values returns true with a greater than operator

AnnaHansen

Board Regular
Joined
Oct 27, 2014
Messages
58
I'm wrestling with odd behavior from vba.

I am trying to compare two numbers which are both converted to double type using cdbl() before comparison.

If greater, then do X. (else nothing)

However, when the two values are equal (in this case, 60604.02), the statement is evaluating true and doing X when I want it to not do X.

I'm baffled as to why this would be. I have found several explanations online that have to do with comparing strings and numbers, but nothing with odd results comparing two numbers.

<code>
Dim dblMyNum As Double
Dim dblLow As Double

dblLow = CDbl(txtBalTo.Value)
For i = 1 To lngCntAll
dblMyNum = CDbl(varFrame(i, 1))
If dblMyNum > dblLow Then
...
End If
Next i
</code>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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