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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to 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,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

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