|
Post by Admin on Jul 13, 2017 9:46:45 GMT
Sub FindingLastRow()
'PURPOSE: Different ways to find the last row number of a range 'SOURCE: www.TheSpreadsheetGuru.com
Dim sht As Workshеет Dim LastRow As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
'Ctrl + Shift + End LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
'Using UsedRange sht.UsedRange 'Refresh UsedRange LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
'Using Table Range LastRow = sht.ListObjects("Table1").Range.Rows.Count
'Using Named Range LastRow = sht.Range("MyNamedRange").Rows.Count
'Ctrl + Shift + Down (Range should be first cell in data set) LastRow = sht.Range("A1").CurrentRegion.Rows.Count
End Sub
Sub FindingLastColumn()
'PURPOSE: Different ways to find the last column number of a range 'SOURCE: www.TheSpreadsheetGuru.com
Dim sht As Worksheet Dim LastColumn As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
'Ctrl + Shift + End LastColumn = sht.Cells(7, sht.Columns.Count).End(xlToLeft).Column
'Using UsedRange sht.UsedRange 'Refresh UsedRange LastColumn = sht.UsedRange.Columns(sht.UsedRange.Columns.Count).Column
'Using Table Range LastColumn = sht.ListObjects("Table1").Range.Columns.Count
'Using Named Range LastColumn = sht.Range("MyNamedRange").Columns.Count
'Ctrl + Shift + Right (Range should be first cell in data set) LastColumn = sht.Range("A1").CurrentRegion.Columns.Count
End Sub
|
|
|
Post by Admin on Jul 13, 2017 9:49:24 GMT
i personally prefer:
LastRow = sht.Cells(sht.Rows.Count, 1).End(xlUp).Row
LastColumn = sht.Cells(1, sht.Columns.Count).End(xlToLeft).Column
|
|