JackDanIce
Well-known Member
- Joined
- Feb 3, 2010
- Messages
- 9,922
- Office Version
- 365
- Platform
- Windows
Hi,
Using following code to return last used row number and receiving 1004 run-time error, wks is an object:
Intermediate window debug:
This started happening today, yesterday without error and no change to code
TIA,
Jack
Using following code to return last used row number and receiving 1004 run-time error, wks is an object:
Rich (BB code):
Public Function LastRow(ByRef wks As Worksheet, Optional ByRef xCol As Long = 0) As Long
'Returns row number of last used cell on a specified sheet in an optional column (A if not specified)
LastRow = 0
With wks
If xCol = 0 Then
'On Error Resume Next
Debug.Print TypeName(wks) & " " & wks.Name
LastRow = .Cells.Find(what:="*", After:=.Cells(1, 1), lookat:=xlPart, LookIn:=xlFormulas, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
'On Error GoTo 0
Else
LastRow = .Cells(.Rows.Count, xCol).End(xlUp).Row
End If
End With
End Function
Rich (BB code):
Worksheet Investors
TIA,
Jack
Last edited: