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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,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