Last active
August 29, 2015 14:01
-
-
Save MartinP7r/02685ace6778372cbcea to your computer and use it in GitHub Desktop.
returns the (actual) last row of the current Excel Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function endOfSheet(Optional targetSheet As Worksheet) As Long | |
'' returns the (actual) last row of the current sheet | |
' this is far better than using '65536' or whatever the current row size might be, | |
' especially since .xlsx has 2^20 (1048576), not 2^16. | |
If targetSheet Is Nothing Then | |
Set targetSheet = ActiveWorkbook.ActiveSheet | |
End If | |
endOfSheet = targetSheet.Rows.Count | |
End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function lastUsedRow(Optional targetSheet As Worksheet) As Long | |
'' returns the last used row in the current worksheet | |
' for columns A:E in this example -- change Range below as needed | |
' dependencies: endOfSheet() -- actual last row of current sheet | |
If targetSheet Is Nothing Then | |
Set targetSheet = ActiveWorkbook.ActiveSheet | |
End If | |
lastUsedRow = targetSheet.Range("A" & endOfSheet(targetSheet)).End(xlUp).Row | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment