Clear data in a row when certain text appear in a cell

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello world,

I am stacked here with a challenge and I need your help pull me out:


I have a column that contains list of items so I need a script that looks for a specific item in that column say "Book" and when found, clear data for the row that contains the item "book".

I am just confused, how to write the loop.


My table starts from A7 to Q100 and the column with the list of items is column C

Thanks in advance
Kelly
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
How about
Code:
Sub delrws()
   With Range("C7", Range("C" & Rows.Count).End(xlUp))
      .Replace "Book", "=XXX", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
   End With
End Sub
 
Upvote 0
Okay thanks.

How do I point it to the sheet i want it to handle?

Say Sheet1
 
Upvote 0
Like this
Code:
Sub delrws()
   With Sheets("Sheet1").Range("C7", Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp))
      .Replace "Book", "=XXX", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
   End With
End Sub
 
Upvote 0
Oh nice, it's working nice now. Thanks again

But can you explain the script to me a bit?


Regards
Kelly
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback.

Code:
Sub delrws()
   With Sheets("Sheet1").Range("C7", Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp))
      .Replace "Book", "=XXX", xlWhole, , False, , False, False   ' Replaces Book with =XXX which causes a formula error
      .SpecialCells(xlFormulas, xlErrors).EntireRow.Delete        ' Finds all cells with a formula error & deletes that row
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,690
Messages
6,167,666
Members
452,131
Latest member
MichelleH77

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