Individually Count Multiple Rows

bkalma

New Member
Joined
Nov 10, 2016
Messages
11
I am trying to write an array formula that will individually count the number of values in a set of rows and return the maximum count. For example, I would like the formula to return a value of 4 for the following table as the maximum number of values in a single row is 4 (row 3):

111
11
1111
1
111

<tbody>
</tbody>

Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the forum.

If your range is A1:E5, try this:

=MAX(SUBTOTAL(2,OFFSET($A$1:$E$1,ROW($A$1:$E$5)-1,0)))

confirmed with Control+Shift+Enter, not just enter.

Note that this formula will only count numeric values, and ignore text values. If you want to count text values as well, change the 2 to a 3.

Let me know if this helps.
 
Upvote 0
Thanks Eric, the formula works, but I forgot to mention that the actual range for my data is D23:AC46. How should I modify the formula to work for any range?

bkalma.
 
Upvote 0
I manged to get it working using the following (Entered as an array formula):

=MAX(SUBTOTAL(2,OFFSET($D$23:$AC$23,ROW($D$23:$AC$46)-ROW($D$23:$AC$23),0)))

Thanks again for the help.

bkalma.
 
Upvote 0
Would there also be a way to write another formula which returns the number of the row with maximum count?

bkalma.
 
Upvote 0
I manged to get it working using the following (Entered as an array formula):

=MAX(SUBTOTAL(2,OFFSET($D$23:$AC$23,ROW($D$23:$AC$46)-ROW($D$23:$AC$23),0)))

Thanks again for the help.

bkalma.

Control+shift+enter, not just enter:

=MAX(MMULT((D23:AC46=1)+0,TRANSPOSE(COLUMN(D23:AC46)^0)))
 
Upvote 0
Control+shift+enter, not just enter:

=MAX(MMULT((D23:AC46=1)+0,TRANSPOSE(COLUMN(D23:AC46)^0)))

Would there also be a way to write another formula which returns the number of the row with maximum count?

bkalma.

Row\Col
D​
1​
max
2​
4​
3​
max count
4​
1​
5​
row(s)
6​
25​
7​
8​

<tbody>
</tbody>


In D2 control+shift+enter, not just enter:

=MAX(MMULT((D23:AC46=1)+0,TRANSPOSE(COLUMN(D23:AC46)^0)))

In D4, control+shift+enter:

=SUM(IF(MMULT((D23:AC46=1)+0,TRANSPOSE(COLUMN(D23:AC46)^0))=D2,1))

In D6 control+shift+enter and copy down:

=IF(ROWS($D$6:D6)<=$D$4,SMALL(IF(MMULT(($D$23:$AC$46=1)+0,TRANSPOSE(COLUMN($D$23:$AC$46)^0))=$D$2,ROW($D$23:$D$46)),ROWS($D$6:D6)),"")

The latter yields the native row numbers on which the most number of 1's occur.

If it's any number, not just 1, change in the formulas the occurrences of:

(D23:AC46=1)+0

to:

ISNUMBER(D23:AC46)+0
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,305
Members
449,150
Latest member
NyDarR

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