Counting the # of rows with a value in an excel range

John MCarthy

New Member
Joined
Mar 30, 2011
Messages
13
Hi,

I am working with a table of data in excel. Under each column I want to count the number of rows to the left of the column that have at least one cell with a number >0 (greater than 0) in the row.

I have been trying variations of COUNT and COUNTIF and am not having any success - can anyone pls provide a formula for this?

Thanks,

John
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,539
How about something like:
=SUMPRODUCT(--((A3:A32+B3:B32+C3:C32+D3:D32)>0))
... that's if I've understood your question correctly, of course.
 

John MCarthy

New Member
Joined
Mar 30, 2011
Messages
13
Hi Glenn,

I tried that on a range that has 4 rows and 10 columns.

Each of the rows has at least one number in it so I would expect an answer of 4, however the answer I got was 7.

What I want the formula to do is pickup each time there is a number in one of the cells in each row and count that as 1.

E.g. if the table has 10 rows and 10 columns, and 6 of the row have numbers (i.e. 4 are blank) the answer would be 6.

Any further suggestions?

Thanks,

John
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,539
Show your formula ... if you'd adjusted my formula as I'd expected the maximum possible result would have been 4.
 

John MCarthy

New Member
Joined
Mar 30, 2011
Messages
13

ADVERTISEMENT

=sumproduct(--((p31:y31+p32:y32+p33:y33+p34:y34)>0))
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,539
That's not what I did. My logic with your data would be:
=sumproduct(--((p31:p34+q31:q34+r31:r34+s31:s34+t31:t34+u31:u34+v31:v34+w31:w34+x31:x34+y31:y34)>0))
 

John MCarthy

New Member
Joined
Mar 30, 2011
Messages
13

ADVERTISEMENT

Works perfrectly!

Thanks Glenn - you are a legend.

John
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
This generic version will work for any range, whatever the size

=SUMPRODUCT((COUNTIF(OFFSET(range,ROW(range)-MIN(ROW(range)),0,1),">0")>0)+0)

so for your example using the range P31:Y34 this will count the number of rows with at least one value greater than zero

=SUMPRODUCT((COUNTIF(OFFSET(P31:Y34,ROW(P31:Y34)-MIN(ROW(P31:Y34)),0,1),">0")>0)+0)
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,539
This generic version will work for any range, whatever the size

=SUMPRODUCT((COUNTIF(OFFSET(range,ROW(range)-MIN(ROW(range)),0,1),">0")>0)+0)

so for your example using the range P31:Y34 this will count the number of rows with at least one value greater than zero

=SUMPRODUCT((COUNTIF(OFFSET(P31:Y34,ROW(P31:Y34)-MIN(ROW(P31:Y34)),0,1),">0")>0)+0)
That's much more elegant ... top marks.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,924
Members
414,416
Latest member
Nobu

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
Top