Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row count where data exists

Tags:

range

excel

vba

I need to count the total number of rows that have data. I want to be able to use this on multiple sheets with different amounts of data rows.

I cannot figure out generic code that will count the number of rows from A1-A100 or A1-A300.

I am trying to use something like this.

i = ActiveWorkbook.Worksheets("Sheet1").Range("A2 , Range("A2").End(xlDown)).Rows.Count
like image 653
Patrick Wilson Avatar asked Aug 06 '13 19:08

Patrick Wilson


1 Answers

Assuming that your Sheet1 is not necessary active you would need to use this improved code of yours:

i = ActiveWorkbook.Worksheets("Sheet1").Range("A2" , Worksheets("Sheet1").Range("A2").End(xlDown)).Rows.Count

Look into full worksheet reference for second argument for Range(arg1, arg2) which important in this situation.

like image 56
Kazimierz Jawor Avatar answered Sep 19 '22 12:09

Kazimierz Jawor