Run-time error '1004', unclear why

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

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
Intermediate window debug:
Rich (BB code):
Worksheet Investors
This started happening today, yesterday without error and no change to code

TIA,
Jack
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Ignore, prior, I had an error causing stack space issue, which I fixed, but this error kept coming in. Restarted Excel and no-longer occurs.

Thanks for reading anyway
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top