Count Rows with VBA

J

jdwhytie

I am trying to code some VBA for a spreadsheet. Not all th
spreadsheets I will be using it on are of exactly the same length, so
am trying to find a way to get a count of all of the rows that hav
information in them so I can use that to set up my references.

Is there a way to do this short of searching for an empty row? I wa
thinking there might be a property that would give me a row count bu
have been unable to find anything to do what I need.

Thanks
-Jak
 
N

Norman Jones

Hi Jake,

Using column A to establish the last row, try:

: Cells(Rows.Count, "A").End(xlUp).Row

---
Regards,
Norman



MsgBox Cells(Rows.Count, "A").End(xlUp).Address
 
C

Chip Pearson

Jake,

There are a variety of ways to do this, depending on the
organization of your worksheet. For example,

Dim NumRows As Long
NumRows = Worksheets("Sheet1").UsedRange.Rows.Count
' or
NumRows =
Worksheets("Sheet1").Cells(Rows.Count,"A").End(xlUp).Row


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top