Finding the Last Row or Column three different ways in Excel VBA - Code Included

Опубликовано: 06 Октябрь 2024
на канале: EverydayVBA
51,472
264

Grab the Free VBA Quick Reference Guide
https://www.chrisjterrell.com/excel-v...
So how do you find the last row or column using VBA. In this video I show you 3 different ways to find that last row.

We use a
1) SepcialCells with the xlCellTypeLastCell for a Sheet
2) We do the same for a a current region range with the help of some math
3) We use the Cells.End(xlUP)

These all work well which is your favorite?

CODE:
===========
Sub LastRow()

slr = Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Row
scl = Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Column

rrw = Range("B12").CurrentRegion.Row + Range("B12").CurrentRegion.Rows.Count - 1
rcl = Range("B12").CurrentRegion.Column + Range("B12").CurrentRegion.Columns.Count - 1

crw = Cells(100, 2).End(xlUp).Row
'xlLeft doesnt work for .End

End Sub