Find Method Error

daniel22bg

New Member
Joined
Nov 21, 2008
Messages
31
Hello, i have the following piece of VBA code, enclosed at the bottom. I would like to search for a word in the whole row. If the word is found, i would like select and hide the row, if the word is not found, I would like to proceed with the next row.

However, whenever the word is not found, I get and error ... Can you please help? In what way can handle the error situation or the situation where the word is not found in the row?

Code:
For i = 3 To k

Rows(i).Select

    Selection.Find(What:=SearchVar, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Select
    Set rFound = Selection
        
    If Not rFound Is Nothing Then
        rFound.EntireRow.Hidden = True
    End If
    
Next i
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Use rFound for the result of the find.
Code:
For I =  3 To K
 
   Set rFound = Rows(I).Find(What:=SearchVar, After:=Cells(I,1), LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
 
   If Not rFound Is Nothing Then
         rFound.EntireRow.Hidden= True
   End If
 
Next I
[/code]
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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