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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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