selection.Find sometimes works sometimes not

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
140
Office Version
  1. 365
  2. 2019
Hi,

I've got this section of code that runs perfectly well in another sub but when I move it to a new sub I get a runtime error 91. Any help would be really appreciated. From Selection.find to .Activate highlights yellow

Sheets("ADP_Times_All_Teams").Select
Selection.Find(What:="AguirreValinda", After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, -4).Select
Selection.Copy
Sheets("Juliya Hours").Select
Range("C4").Select
ActiveSheet.Paste

Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
If you want it to search the whole sheet, change:
Code:
[COLOR=#333333]Selection.Find(...
to
[/COLOR]
Code:
[COLOR=#333333]Cells.Find(...[/COLOR]
Also, error 91 is the error message it will return if it cannot find what you are looking for. You probably need to account for that possibility with some error handling.
 
Upvote 0
I was using
If Find Is Nothing Then Exit Sub
for the error handling but it gives me an error now as well.
 
Upvote 0
Here is one way:
Code:
    Dim cell As Range

    Sheets("ADP_Times_All_Teams").Select
    On Error Resume Next
    Set cell = Cells.Find(What:="AguirreValinda", After:=ActiveCell, LookIn:= _
        xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False)
    On Error GoTo 0
    
    If Not cell Is Nothing Then
        Sheets("Juliya Hours").Range("C4") = cell.Offset(0, -4)
    End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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