Count Used Rows

Sylvan

New Member
Joined
Nov 11, 2010
Messages
29
I need to count the number of used rows in a range. The two problems are that I can't use VBA -- must use a formula, and I can't be sure that any particular cell in the range will have any information in it.

Right now I'm using:

=IF(COUNTA(OFFSET(A17,1,0,5000,10))=0,0,SUM(COUNTA(OFFSET(A17,1,0,5000,10))/COUNTA(OFFSET(A17,1,0,1,10))))

but this only works if all rows have the same number of used cells. I would use nested ifs, but there are ten columns and you can only use 7 nested ifs.

Any ideas?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I need to count the number of used rows in a range. The two problems are that I can't use VBA -- must use a formula, and I can't be sure that any particular cell in the range will have any information in it.

Right now I'm using:

=IF(COUNTA(OFFSET(A17,1,0,5000,10))=0,0,SUM(COUNTA(OFFSET(A17,1,0,5000,10))/COUNTA(OFFSET(A17,1,0,1,10))))

but this only works if all rows have the same number of used cells. I would use nested ifs, but there are ten columns and you can only use 7 nested ifs.

Any ideas?
Let's assume this is your data:

Book1
ABCDEFGHIJ
130
2
37354
4
580
6
744
8
9
10
1158
12926955
13
14
15
16
17
1892
1982
20
Sheet1

You want to count how many rows in the range have at least one entry.

In the formula:
  • Array is a defined name that refers to: ={1;1;1;1;1;1;1;1;1;1}
=SUMPRODUCT(--(MMULT(--(A1:J20<>""),Array)>0))

Array is a vertical array of ones equal to the number of columns in the range. In your range there are 10 columns so Array contains 10 ones.

If you had "many" columns you wouldn't necessarily want to do something like this:

{1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;etc;}

You could use this array entered** version:

=SUM(--(MMULT(--(A1:J20<>""),TRANSPOSE(COLUMN(A1:J20)^0))>0))

** array formulas need to be entered using the key combination of CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT key then hit ENTER.
 
Upvote 0
The second of those works until I run VBA code which pastes into the range and then the range reference in the formula is replaced by #REF!.
 
Upvote 0
The second of those works until I run VBA code which pastes into the range and then the range reference in the formula is replaced by #REF!.
Hmmm...

If you can use code to paste into the range then why this:

I can't use VBA -- must use a formula
Maybe this:

=SUM(--(MMULT(--(INDIRECT("A1:J20")<>""),TRANSPOSE(COLUMN(INDIRECT("A1:J20"))^0))>0))

Still array entered.
 
Upvote 0
That works like a charm, thanks so much.

Just meant that I wanted the solution to be a formula rather than VBA so that the number would change automatically if data was added or deleted.
 
Upvote 0
That works like a charm, thanks so much.

Just meant that I wanted the solution to be a formula rather than VBA so that the number would change automatically if data was added or deleted.
You're welcome. Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,754
Members
452,940
Latest member
rootytrip

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