"RANKIF" using SUMPRODUCT with dynamic range help

millawitch

New Member
Joined
Jun 20, 2012
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm new to the MrExcel forum and this is my first post. :)

I have a "RANKIF" formula using SUMPRODUCT:

=SUMPRODUCT(--($B4=$B$4:$B$100),--($F4<$F$4:$F$100))+1

which works fine. At the moment "F" is the last column, but the table will expand to the right so the last column reference will always change. In other words, $F4<$F$4:$F$100 can change to $G4<$G$4:$G$100, $H4<$H$4:$H$100, etc and I want the formula to always look for data in the last column.

How do I make it work in this scenario?

Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi and welcome to Mr Excel Forum,

Assuming there is a header in the last column, in row 3, and it is Scores (adjust to suit) maybe this can work

=SUMPRODUCT(--($B4=$B$4:$B$100),--(INDEX($A$4:$Z$100,ROWS($1:1),MATCH("Scores",$3:$3,0)) < INDEX($A$4:$Z$100,0,MATCH("Scores",$3:$3,0))))+1

<INDEX($A$4:$z$100,0,match("scores",$3:$3,0))))+1
copy down

M.</INDEX($A$4:$z$100,0,match("scores",$3:$3,0))))+1
 
Upvote 0
Hi Marcelo,


Thanks for your input. At the moment I'm just starting to build this database but it will be converted into a Excel 2007 table, and you can't have column headers with repeated names, so this wouldn't work. :(

I tried to test your formula, but I didn't understand why the INDEX used $A$4:$Z$100,ROWS($1:1) if my table headers are in row 3 and data starts in row 4 (the RANKIF formula is in column A). Also, the last INDEX doesn't seem to be referencing a range, but I might be wrong.

I can't have VBA, but if adding helper cells makes it easier, then perhaps is the way to go.

I've tested with 2 helper cells on the side

H
9 6 =MAX(COUNTA($A4:$KN4))
10 $F$4 =ADDRESS(ROW($B4),$H$9)

and got =SUMPRODUCT(--($B4=$B$4:$B$100),--(INDIRECT($H10)<$F$4:$F$100))+1 to work, but don't know how to tackle the range part...


Any thoughts?
 
Upvote 0
Hi Marcelo,


Thanks for your input. At the moment I'm just starting to build this database but it will be converted into a Excel 2007 table, and you can't have column headers with repeated names, so this wouldn't work. :(

I tried to test your formula, but I didn't understand why the INDEX used $A$4:$Z$100,ROWS($1:1) if my table headers are in row 3 and data starts in row 4 (the RANKIF formula is in column A). Also, the last INDEX doesn't seem to be referencing a range, but I might be wrong.

I can't have VBA, but if adding helper cells makes it easier, then perhaps is the way to go.

I've tested with 2 helper cells on the side

H
9 6 =MAX(COUNTA($A4:$KN4))
10 $F$4 =ADDRESS(ROW($B4),$H$9)

and got =SUMPRODUCT(--($B4=$B$4:$B$100),--(INDIRECT($H10)<$F$4:$F$100))+1 to work, but don't know how to tackle the range part...


Any thoughts?

The last INDEX
INDEX($A$4:$Z$100,0,MATCH("Scores",$3:$3,0))
uses 0 as the second parameter (row number) to return an array - all the values present in the column. For example, if Scores (the supposed header) is in column F then it returns F4:F100.

Could you provide a data sample?

M.
 
Upvote 0
Hi Marcelo,


Thanks for your input. At the moment I'm just starting to build this database but it will be converted into a Excel 2007 table, and you can't have column headers with repeated names, so this wouldn't work. :(

The formula requires that there is a header in the column with the scores to be ranked (Scores or whatever, but i must know what it is), not repeated in anyway.

M.
 
Upvote 0
The formula requires that there is a header in the column with the scores to be ranked (Scores or whatever, but i must know what it is), not repeated in anyway.

M.

Hi Marcelo,

Thank you for your time and for explaining the INDEX "trick"! I don't know Excel that much, I just bang my head hard enough in a wall until something works (with a lot of forum tips I might say). ;) But as I said, I can't have the same header repeated as this will be a table.
 
Upvote 0
But as I said, I can't have the same header repeated as this will be a table.

Maybe i'm not making myself clear (English is my second language). As i said in #5 (above) the formula requires an unique header in row 3 in the column that contains the scores (values) to be ranked. With repeated headers the formula wouldn't work

Please, try to post a data sample. To do this:
Select a relevant part of your data, say 10 rows, including headers
Put borders
Copy (Ctrl+C)
Paste (Ctrl+V) in the forum reply page.

Doing so someone can help you.

M.
 
Upvote 0
Actually, I got it to work creating 4 helper cells (with =ADDRESS(ROW($A6),$K$1) inside the table, copied down):

K1 Columns count: 11 =MAX(COUNTA($A$5:$NY$5))</SPAN>
K2 Last column: $K$100 =ADDRESS(100,$K$1)</SPAN>
K3 Range: $K$6:$K$100 =ADDRESS(ROW($A6),$K$1)&":"&ADDRESS(100,$K$1)</SPAN>

and the RANKIF function as

=SUMPRODUCT(--($C6=$C$6:$C$100),--(INDIRECT($B6)<INDIRECT($K$3)))+1

A bit cumbersome - does someone have a better solution? I'd appreciate some help!
 
Upvote 0
</SPAN>

and the RANKIF function as

=SUMPRODUCT(--($C6=$C$6:$C$100),--(INDIRECT($B6)<INDIRECT($K$3)))+1

A tip:
When posting a formula that uses less than put spaces around the symbol < . Otherwise the forum software takes it as a special character and truncates the formula.

One more time: we need a data sample to see if a better solution is possible.

M.
 
Upvote 0
A tip:
When posting a formula that uses less than put spaces around the symbol < . Otherwise the forum software takes it as a special character and truncates the formula.

One more time: we need a data sample to see if a better solution is possible.

M.

Oops, only now I saw that the formula was cut out. :rolleyes: Here's a sample (columns E-G and I will have data but are irrelevant for this):


Excel 2007
ABCDEFGHIJK
1Columns count:11
2Last column:$K$100
3Range:$K$6:$K$100
4
5RankLast ColumnSubgroupShareholderEFGShares ReceivedITotal SharesPercentage
61$K$6TotalsTotals1,392,7101,392,710100.00%
71$K$7Investor Group AInvestor Group A1,357,95597.50%
82$K$8Investor Group AInvestor 11,250,0001,250,00089.75%
93$K$9Investor Group AInvestor 255,50055,5003.99%
104$K$10Investor Group AInvestor 352,45552,4553.77%
111$K$11Investor Group BInvestor Group B34,7552.50%
124$K$12Investor Group BInvestor 47,7557,7550.56%
133$K$13Investor Group BInvestor 512,00012,0000.86%
142$K$14Investor Group BInvestor 615,00015,0001.08%
Sample
Cell Formulas
RangeFormula
K1=MAX(COUNTA($A$5:$NY$5))
K2=ADDRESS(100,$K$1)
K3=ADDRESS(ROW($A6),$K$1)&":"&ADDRESS(100,$K$1)
A6=SUMPRODUCT(--($C6=$C$6:$C$100),--(INDIRECT($B6)$K$3)))+1
B6=ADDRESS(ROW($A6),$K$1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,583
Messages
6,131,557
Members
449,655
Latest member
Anil K Sonawane

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