Macro to removed rows with exact text

Awebber1993

New Member
Joined
Jun 26, 2018
Messages
2
I'm trying to create a macro which allow me to remove a row if it contains an exact word. When I extract data, the column may contain the word "Renewal" or "Renewal & Additional". What I'm trying to achieve is to remove all the rows that contain the word "Renewal" and not the rows that contain "Renewal & Additional". So far I have come across this coding and it will remove all rows that contain the word "Renewal", is there a way is can be adjusted?

With ActiveSheet
.AutoFilterMode = False
With Range("e1", Range("e" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Renewal*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this:
Code:
Sub Filter_Me_Please()
'Modified 6/26/18 4:40 AM EDT
Dim Lastrow As Long
Dim c As Long
Dim s As String
c = "5" ' Column Number Modify this to your need
s = "Renewal" 'Saerch Value Modify to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row
With ActiveSheet.Cells(1, c).Resize(Lastrow)
    .AutoFilter 1, s
    counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
End Sub
 
Upvote 0
If the word "Renewal" is the only text in a cell in Column E, then you can use this code to delete those rows...
Code:
[table="width: 500"]
[tr]
	[td]Columns("E").Replace "Renewal", "#N/A", xlWhole, , False, , False, False
Columns("E").SpecialCells(xlConstants, xlErrors).EntireRow.Delete[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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