-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindLastColOfWorksheet
35 lines (33 loc) · 1.1 KB
/
FindLastColOfWorksheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Public Function FindLastColOfWorksheet() As Long
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'DATE AUTHOR
'7/17/19 Alejandro
'
'APPLICATION: Excel
'
'PURPOSE
'Returns the last column of a worksheet that contains any data (including formatting) in any of the
'cells in any of its columns
'
'PARAMETERS
' N/A
'
'TICKETS
'Date Ticket Description
'N/A
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Turn off error handling in the event that the entire worksheet is blank
On Error Resume Next
'Starting from the very last row/col of the worksheet, find the first used cell searching row
'by row, right to left, going up the worksheet
FindLastColOfWorksheet = Cells.Find( _
What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
'Turn default error handling back on
On Error GoTo 0
End Function