forked from farishadi/Excel_Macro_References
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLastCellAddress
More file actions
21 lines (16 loc) · 813 Bytes
/
LastCellAddress
File metadata and controls
21 lines (16 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Public Function lastCellAdd() As String
'this function retrieves the row and column of the last most cell in the worksheet
Dim lastColumn As Integer
Dim lastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
lastRow = Cells.Find(What:="*", after:=Cells(Rows.Count, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards by Columns.
lastColumn = Cells.Find(What:="*", after:=Cells(1, Columns.Count), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
lastCellAdd = Cells(lastRow, lastColumn).Address(False, False)
Else
lastCellAdd = "X"
End If
End Function
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
lLastColumn = Cells(1, Columns.Count).End(xlToRight).Column