If string detected in a cell, clear entire row

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I'm struggling with this job: for each cell in a column, I have to check if the letter "I" is contained.
If yes, clear the entire row.

Now, with the following code something is wrong (all rows are cleared, also if "I" is not contained).

Code:
If InStr(1, cell, “I”) > 0.5 Then cell.EntireRow.Clear


Thank's in advance.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hello everybody.

I'm struggling with this job: for each cell in a column, I have to check if the letter "I" is contained.
If yes, clear the entire row.

Now, with the following code something is wrong (all rows are cleared, also if "I" is not contained).

Code:
If InStr(1, cell, “I”) > 0.5 Then cell.EntireRow.Clear


Thank's in advance.

Try using .Value for the InStr,

Code:
InStr(1, cell.Value, “I”)
 
Upvote 0
If your cells contain values, rather than formulas, how about
Code:
Sub dellIRows()
   With Range("[COLOR=#ff0000]J:J[/COLOR]")
      .Replace "*I*", "=XXX", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
   End With
End Sub
Change value in red to suit
 
Upvote 0
@Fluff and @JonXL thank you, both the solution are ok (Jon, at first I had a problem with my file and because of that it has not worked until I fixed it).
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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