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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
There are many variables eg.
Complete
Completed
Complete in March
Completed Last Year etc.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,893
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,893
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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
 

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,652
Messages
5,838,603
Members
430,557
Latest member
MK15

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
Top