Delete Rows with Multiple Strings

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
I have the following and it works for any row that starts with the word "Complete". What do I need to do to also include deleting rows that start with "801730-TECH-YEG-" ?

Code:
  Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
    Do
    Set c = SrchRng.Find("*Complete*", LookIn:=xlValues)
    If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
There are many variables eg.
Complete
Completed
Complete in March
Completed Last Year etc.
 
Upvote 0
I have the following and it works for any row that starts with the word "Complete". What do I need to do to also include deleting rows that start with "801730-TECH-YEG-" ?

Code:
  Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
    Do
    Set c = SrchRng.Find("*Complete*", LookIn:=xlValues)
    If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing

What is in Column A... constants or formula?
 
Upvote 0
Constant (Text)
Okay, give this macro a try then...
Code:
Sub DeleteCertainRows()
  Dim Addr As String
  Addr = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Address
  Range(Addr) = Evaluate(Replace("IF(ISNUMBER(SEARCH(""complete"",@)),""#N/A"",@)", "@", Addr))
  Range(Addr) = Evaluate(Replace("IF(ISNUMBER(SEARCH(""801730-TECH-YEG-"",@)),""#N/A"",@)", "@", Addr))
  Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End Sub
 
Upvote 0
Okay, give this macro a try then...
Code:
Sub DeleteCertainRows()
  Dim Addr As String
  Addr = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Address
  Range(Addr) = Evaluate(Replace("IF(ISNUMBER(SEARCH(""complete"",@)),""#N/A"",@)", "@", Addr))
  Range(Addr) = Evaluate(Replace("IF(ISNUMBER(SEARCH(""801730-TECH-YEG-"",@)),""#N/A"",@)", "@", Addr))
  Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End Sub

Works like a charm. Thanks very much Rick.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,770
Members
449,095
Latest member
m_smith_solihull

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