Delete Row based on cell content

deduwa

Board Regular
Joined
Jul 28, 2015
Messages
110
Hi,

Is it possible to code something that does the following in the current sheet (Sheet1).

(I have 2 tabs which are Sheet1, AA)

1. If cell value in F1 of "AA" tab = 1 then in Sheet1 find the term ABC and delete the entire row that contains this ABC term

2. If cell value in F1 of "AA" tab = 2 then in Sheet1 find the term UVW and XYZ and delete the two rows entirely that contain these two terms

Hope I have made it clear.

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
untested,

try this on a copy of your file:

Code:
Sub DeleteRows()
Application.ScreenUpdating = False

If Worksheets("AA").Range("F1") = 1 Then
    With Worksheets("Sheet1").Cells
        .Replace "ABC", True, xlWhole ' can also use *John* if searching for any part
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With
End If


If Worksheets("AA").Range("F1") = 2 Then
    With Worksheets("Sheet1").Cells
        .Replace "UVW", True, xlWhole ' can also use *John* if searching for any part
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With
    
    With Worksheets("Sheet1").Cells
        .Replace "XYZ", True, xlWhole ' can also use *John* if searching for any part
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With
End If

Application.ScreenUpdating = True
End Sub

hth,

Ross
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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