Number of rows/columns occupied

W

Will

Is there a function which counts the number of
rows / columns in an Excel worksheet
which contain something (i.e. are not empty)?
 
M

Mike H

Hi,

Alt+F11 to open vb editor, right click 'This Workbook' and insert module and
paste these 2 UDF's below in

call with

=usedrows()
=usedcolumns()

Function UsedRows() As Long
UsedRows = ActiveSheet.UsedRange.Rows.Count
End Function

Function UsedColumns() As Long
UsedColumns = ActiveSheet.UsedRange.Columns.Count
End Function

Mike
 
R

Rick Rothstein

Those functions will count blank rows and/or blank columns that are located
within the UserRange (plus it is possible for the UsedRange to contain blank
rows and/or blank columns after the last piece of data in a row or column).
 
S

Shane Devenshire

Hi,

As stated the answer is no. You have asked for A function which counts all
the occupied rows and columns in a worksheet. There is no function that will
do both at once, rows and columns. Also, there is no built in function which
will calculate the number of occupied rows in all columns at once.

What you could do is insert a new column A and a new row in position 1,
enter the formula =COUNTA(B2:IV2) in A2 and copy it down as far as you want
65536 or 1,048,576 (2007). Then in A1 enter the formula =SUM(A2:A65536)

This will count the number of rows that have anything on them. You can do
something similar for columns.

Also, none of these formulas consider whether the cells are formatted if
that is important.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top