Friday, March 24, 2017

Finding last row, last column, and last used cell

make sure you declare the variable where you want to store the last row as long:

e.g:

Dim lrow As Long


Find last row:

lRow = Cells(Rows.Count, 1).End(xlUp).Row
where it says cells(rows.count, 1); the 1 refers to the column to be used to get the last row, e.g if you want to find the last row using the values in column D, then you would replace 1 by 4.



Find last column:

lCol = Cells(1, Columns.Count).End(xlToLeft).Column
Last Used Cell:
MsgBox Range("A1").SpecialCells(xlCellTypeLastCell).Address
https://www.excelcampus.com/vba/find-last-row-column-cell/

No comments:

Post a Comment