PDA

View Full Version : Solved: Difference between 2 count last row/column command



cavemonkey
06-13-2007, 10:59 PM
hi

I'm wondering what's the difference between these 2 code?



lrow = ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row


and this



lrow = ActiveSheet.Range("A65536").End(xlUp).Row


since these 2 are to count last row then what about counting column? for the first code, will it work if I just change the rows to columns?


lrow = ActiveSheet.Range("A" & ActiveSheet.Columns.Count).End(xlUp).Column


Please advise.

mikerickson
06-14-2007, 12:17 AM
The difference between the codes is that

lrow = ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row will find the last row in column A that has an entry.

lrow = ActiveSheet.Range("A65536").End(xlUp).Row will find the last row above 65536 that has an entry. Before 2007 came out there was no practical difference.

To find the last column in row 1, I would use this code.

LCol = ActiveSheet.Cells(1,ActiveSheet.Columns.Count).End(xlToLeft).Column

Bob Phillips
06-14-2007, 01:13 AM
Rows.Count is a built-in constant, it is the number of rows in a worksheet. In Excel pre-2007, that is 65536, in 2007 it is 1048576.

Your first bit of code cries out for a With clause



With ActiveSheet
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
End With

cavemonkey
06-21-2007, 07:39 PM
i see thanks a lot!