Search Text and Error Handling

salman94

New Member
Joined
Jun 7, 2018
Messages
21
Hi,

I would like to search a text in my spreadsheet and delete the row partially. If it doesn't find the text, I would like it to move on with the rest of the code. I keep getting the mismatch error here.
' Delete FV ONLY Row

Set rngfind = Cells.Find(What:="FV ONLY", After:=ActiveCell, LookIn:=xlValues).Activate
If Not rngfind Is Nothing Then
Range(ActiveCell, ActiveCell.Offset(0, 2)).Delete
Else
Resume Next
End If​

I also tried but doesn't work either:
Do
Cells.Find(What:="FV ONLY", After:=ActiveCell, LookIn:=xlValues).Activate
Range(ActiveCell, ActiveCell.Offset(0, 2)).Delete
Loop Until Selection Is Nothing
On Error Resume Next​

Would appreciate the help here.

Thanks in advance
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi

Why are you activating a cell if you don't know if it exists?

Just try to find the cell and in case you find it then delete.

Code:
    Set rngfind = Cells.Find(What:="FV ONLY", After:=ActiveCell, LookIn:=xlValues)
    If Not rngfind Is Nothing Then
        Range(rngfind, rngfind.Offset(0, 2)).Delete Shift:=xlShiftUp
    End If

Remark: you usually don't have to use .Select or .Activate in vba.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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