Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of rows in excel with data?

column A has data like this (ie frequent blank cells):

HEADING  <-- this is A1 kfdsl fdjgnm fdkj  gdfkj 4353  fdjk  <-- this is A9 

I would like to be able to get the cell reference of the last cell that has data. So in the above example, I want to return: A9

I have tried this but it stops at the first blank cell (ie returning A4)

numofrows = destsheet.Range("A2").End(xlDown).Row - 1 
like image 800
pjj Avatar asked Jun 10 '11 03:06

pjj


People also ask

What is the formula to count rows in Excel?

ROWS is useful if we wish to find out the number of rows in a range. The most basic formula used is =ROWS(rng). The function counted the number of rows and returned a numerical value as the result. When we gave the cell reference B6, it returned the result of 1 as only one reference was given.


1 Answers

I like this way:

ActiveSheet.UsedRange.Rows.Count

The same can be done with columns count. For me, always work. But, if you have data in another column, the code above will consider them too, because the code is looking for all cell range in the sheet.

like image 167
Tomamais Avatar answered Sep 17 '22 13:09

Tomamais