2 equal values not working properly with rank function

KyleX

New Member
Joined
Jul 11, 2017
Messages
14
I have 2 numbers, both 18.19 in value, but the rank function treats them differently. Usually the rank function will assign the same rank to numbers of the same value, but here it assigns a different value, which is wrecking my otherwise nicely working VBA script. Out of thousands of trials I've only seen this once, in this instance. Here is the data:

BCDEFGHIJ
2Data Rank Data Rank
318.26 2.00 =B4=B9 18.26 2.00 =G4=G9
418.19 3.00 TRUE 18.19 3.00 TRUE
511.65 6.00 11.65 6.00
615.18 5.00 15.18 5.00
718.19 4.00 18.19 3.00
824.42 1.00 24.42 1.00

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
E4=B4=B7
J4=G4=G7
C3=RANK(B3,$B$3:$B$8,0)
C4=RANK(B4,$B$3:$B$8,0)
C5=RANK(B5,$B$3:$B$8,0)
C6=RANK(B6,$B$3:$B$8,0)
C7=RANK(B7,$B$3:$B$8,0)
C8=RANK(B8,$B$3:$B$8,0)
H3=RANK(G3,$G$3:$G$8,0)
H4=RANK(G4,$G$3:$G$8,0)
H5=RANK(G5,$G$3:$G$8,0)
H6=RANK(G6,$G$3:$G$8,0)
H7=RANK(G7,$G$3:$G$8,0)
H8=RANK(G8,$G$3:$G$8,0)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



The second 2 columns are the first columns copy and pasted. Then, all I did was copy the first instance of 18.19 and paste it into the second instance. Now the rank function treats them properly as equals. Why were they not equal before?? I'm so lost I'd really appreciate any insight, even guesses. Thanks!
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Are the numbers coming from a formula?
Try expanding the number of decimal points and you may find the numbers are different.
 
Upvote 0
I checked that and it doesn't seem like there is any noticeable difference in the values. I can bring it out to 20 decimal points, they're all 0s after the first 2, for both values. The values don't even come from formulas! :confused:
Thanks for your reply though!


Book1
BC
2DataRank
318.262.00
418.19000000000000000000000000000000000000000000000003.00
511.656.00
615.185.00
718.19000000000000000000000000000000000000000000000004.00
824.421.00
Sheet1
Cell Formulas
RangeFormula
C3=RANK(B3,$B$3:$B$8,0)
C4=RANK(B4,$B$3:$B$8,0)
C5=RANK(B5,$B$3:$B$8,0)
C6=RANK(B6,$B$3:$B$8,0)
C7=RANK(B7,$B$3:$B$8,0)
C8=RANK(B8,$B$3:$B$8,0)
 
Last edited:
Upvote 0
This sounds like the known floating-point issue with the way Excel calculates.

https://support.microsoft.com/en-us...-rounding-errors-in-floating-point-arithmetic

It may help you out if you specifically rounded your values to 2 decimal places.

Thank you for this. So even though I can bring the decimal places out to as far as I can see, and everything matches, the values still might different in the "background"?

Odd that the countif function treats the values the same, but the rank function treats them differently. Both the methods in the link you provided worked, although I'm a bit wary to use precision as displayed, so I'll just incorporate rounding into my VBA code.

:biggrin:
 
Upvote 0
I'm glad that helped you out. I usually try to round my numbers off to the most significant decimal place I might need, just to avoid any potential issues like this.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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