Run-time error '91' on find operation

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
I'm getting a Run-time error '91': Object variable or with block variable not set on the Cells.Find code below. It works fine when I create it as a macro and run, but not in the VBA code.

Code:
    ' select CSCIs sheet to format
    Set Format_Sheet = Sheets("CSCIs")
    ' activate sheet
    Format_Sheet.Activate
    
    ' find associated documentation cell
    Cells.Find(what:="Associated Documentation", After:=ActiveCell, LookIn:= _
        xlFormulas, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate

    ' set start row to row where title is
    startRow = ActiveCell.Row

Any ideas?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You could try this:

Code:
Dim startRow As Long

On Error Resume Next
startRow = Cells.Find(what:="Associated Documentation", After:=ActiveCell, LookIn:= _
        xlFormulas, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Row

If Err.Number <> 0 Then MsgBox "Not found"

If you get that error with this, it probably means it can't find the text. I added the Err.Number so you can detect those errors. HTH
 
Upvote 0
Thanks, I'll try that. The text is there though, it's a standard section of the report.
 
Upvote 0
The code works, but it's not finding the text. I can go into the worksheet, do a find and it finds it.

Could it be because the text is in a merged cell?

- Added -

No, that's not the reason since it won't find anything, just says not found even if the text isn't in a merged cell.
 
Upvote 0

Forum statistics

Threads
1,226,588
Messages
6,191,889
Members
453,684
Latest member
Gretchenhines

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