Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

ignore neg. values in Rank function VBA

$
0
0

I have a huge file where i want to rank all the values in a column where the value "0" would give me rank one. So far no problems. The main problem that is i also have negative numbers and as long as i have these negative numbers they will always rank "lower" than "0" or any other number.

Is there anyway to exclude the negative numbers from the .Rank function?

I could give them a placeholder number but this defeats the purpose since i want to run this code on several "rankings" and i also need the "real" numbers for other calculations.

Stripped my code some and this is basicly what i run now:

Sub test()
lastrow = Worksheets("Sheet").Range("A65536").End(xlUp).Row
Dim Lista As Range
Set Lista = Sheets("Sheet").Range("A1:A100")


For i = 1 To lastrow
    irRanking = WorksheetFunction.Rank_Eq(Worksheets("Sheet").Cells(i,1) 
.Value, Lista, 1)
    Worksheets("Sheet").Cells(i, 4).Value = irRanking
Next i
End Sub

Or is there another way doing this, skipping .Rank alltogether?

Also have to add that i know its possible using formulas, but i really need a solution in VBA


Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>