Using object model to coult the number of used rows

  • Thread starter Thread starter aaj
  • Start date Start date
A

aaj

Hi

Does any one know how to count the number of used columns and rows in a
sheet via the object model

I know

int m_columncount = m_CurrentWorkSheet.Columns.Count;

gives the total columns, but what I need is a count of the used colums.

Or do I need to write a manual count i.e. manually count how many are used
by by checking each element?

thanks

Andy
 
Debug.Print ActiveSheet.UsedRange.Columns.Count
Debug.Print ActiveSheet.UsedRange.Rows.Count


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi Andy,
What do you want to use the number for ?

For instance the used range starts from cell A1 and may extend
beyond your data as rows deleted don't diminish the used range
unless you delete the phantom rows and possibly save the file.

If you have empty rows at the top, they will not be included with
ActiveSheet.UsedRange.Rows.Count
but empty rows included in the range still count, as do rows at
the bottom that no longer exist after deletions.

If you want to find the last cell in a column with content
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Select
or if you want to find the next available cell after your data in a column
Cells(Rows.Count, ActiveCell.Column).End(xlUp).offset(1,0).Select
 
Hi guys

thanks for the rapid responses

basically I import data rows and columns from spreadsheets that are
generated else where.

When I import, I just need to know how many entries exist in certain
rows/columns before starting.

I'm sure the info you have posted will solve my problems

thanks again

Andy
 
Back
Top