Excel VBA - Counting Negative Values and Ranking Them

ggmkp

New Member
Joined
May 3, 2019
Messages
7
Trying to count the negative values and ranking them from highest count to lowest

626416d1559165121-excel-vba-counting-negative-values-and-ranking-them-capture.png


I was going to use the worksheet function like this

Code:
Set CountRng = range("B1:F1") 
CountApple = Application.WorksheetFunction.CountIf(CountRng, "<0")
But not sure how I can rank them. Maybe I need to use array here?

Result should rank Orange (3), Banana (2) and Apple (1)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If your data begins in A2 (I considered A1 a header), you can place this ARRAY FORMULA (CTRL+SHIFT+Enter) in B2 and fill down.

Code:
=IF($A2<0,MATCH($A2,LARGE(IF($A$2:$A$31<0,$A$2:$A$31),ROW(INDIRECT("1:"&COUNTIF($A$2:$A$31,"<0")))),0),"")

I only had values in A2:A31.

As per Excel's RANK formula, ties will rank equally and the next value will be incremented.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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