Last active
April 10, 2019 08:00
-
-
Save danwagnerco/f3db3e4a12cea028bf03 to your computer and use it in GitHub Desktop.
This file contains 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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | |
'INPUT : Sheet, the worksheet we'll search to find the last row | |
'OUTPUT : Long, the last occupied row | |
'SPECIAL CASE: if Sheet is empty, return 1 | |
'EXAMPLES : | |
' | |
'assume that there is a single | |
'entry on MySheet in cell A5: | |
' | |
'LastRowNum(MySheet) | |
'>> 5 | |
' | |
'assume that EmptySheet is totally empty: | |
' | |
'LastRowNum(EmptySheet) | |
'>> 1 | |
' | |
Public Function LastRowNum(Sheet As Worksheet) As Long | |
If Application.WorksheetFunction.CountA(Sheet.Cells) <> 0 Then | |
LastRowNum = Sheet.Cells.Find(What:="*", _ | |
LookIn:=xlFormulas, _ | |
SearchOrder:=xlByRows, _ | |
SearchDirection:=xlPrevious).Row | |
Else | |
LastRowNum = 1 | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment