-->

VBA - Ranking Highest to Lowest by Counting Negati

2019-09-19 23:35发布

问题:

How to rank highest to lowest by counting negative values?

I would probably use something like this follow by if elseif logic but I can't seems to figure it out

Set CountRng = range("B1:E1") 
CountApple = Application.WorksheetFunction.CountIf(CountRng, "<0")
CountOrange ..
CountBanana ..

If CountApple > CountOrange then or endif...

Maybe there is a better way to do this?

回答1:

You could use this formula:

=SUMPRODUCT(--(COUNTIF(OFFSET($B$1,(ROW($1:$3)-1),0,1,4),"<0")>COUNTIF(B1:E1,"<0")))+1