VBA Delete Entire Row if Contains Certain Text

bigmacneb

Board Regular
Joined
Jul 12, 2005
Messages
93
I've searched on here, but every code I put in gives me an error back. Data in column D, If any of the cells contains "Record Only" I need it to delete the entire row.
Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
MNexcel,
You can only have one subroutine with the name test. Try naming your three subroutines test1, test2 and test3.
 
Upvote 0
moramramesh,

We can not tell what worksheet(s), cells, rows, columns, your raw data is in.

And, we can not tell what the results should look like.

You could improve your chance of getting some help if you post some sample data and a sample of the results you would like to see. See this link for how to post your data. https://www.mrexcel.com/forum/about-...tachments.html

Alternately, you could upload a copy of your file to a free site such as www.box.com. or www.dropbox.com.

Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here.

Include a detailed explanation of what you would like to do referring to specific cells, rows, columns and worksheets.

If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
The posts so far have been regarding deleting rows with specific text, eg. "Record Only". I want to delete rows which contain the text specified in another cell, so that a user can change the text in that cell without having to edit the macro. For example, cell L5 on a tab called “Lookup”, The user can change the contents from “Blue” to “Red” and the next time it is run, the rows with “Red” will be deleted.

Why does the below find no rows to be deleted? What would work?

Last = Cells(Rows.Count, "V").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "V").Value) = "=’Lookup’!L5" Then
Cells(i, "A").EntireRow.delete
End If
Next i
 
Upvote 0
VBA Code:
If Cells(i, "V").Value = Sheets("Lookup").Range("L5").Value Then
Cells(i, "A").EntireRow.Delete

Edited to remove unnecessary brackets left from post 175
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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