Search Range array

Enzo_Matrix

Board Regular
Joined
Jan 9, 2018
Messages
113
I have some code and I want to change the search parameters to an array so I can find "shipped" and "partial - shipped" but not too sure how. Can someone please take a look and give me some guidance?
VBA Code:
Sub DeleteRows()
    
    Dim c As Range
    Dim SrchRng

    Set SrchRng = ActiveSheet.Range("D1", ActiveSheet.Range("D65536").End(xlUp))
    Do
        Set c = SrchRng.Find("shipped", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
    
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this

VBA Code:
Sub DeleteRows()
    Dim c As Range
    Dim SrchRng

    Set SrchRng = ActiveSheet.Range("D1", ActiveSheet.Range("D65536").End(xlUp))
    Do
        Set c = SrchRng.Find("shipped", , xlValues, xlPart)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
End Sub
 
Upvote 0
This macro assumes you have headers in row 1 and your data starts in row 2 with no blank rows.
VBA Code:
Sub DeleteRows()
    With Cells(1, 1).CurrentRegion
        .AutoFilter Field:=4, Criteria1:="=partial - shipped", Operator:=xlOr, Criteria2:="=shipped"
        ActiveSheet.AutoFilter.Range.Offset(1, 0).EntireRow.Delete
    End With
    Range("A1").AutoFilter
End Sub
 
Upvote 0
This macro assumes you have headers in row 1 and your data starts in row 2 with no blank rows.
VBA Code:
Sub DeleteRows()
    With Cells(1, 1).CurrentRegion
        .AutoFilter Field:=4, Criteria1:="=partial - shipped", Operator:=xlOr, Criteria2:="=shipped"
        ActiveSheet.AutoFilter.Range.Offset(1, 0).EntireRow.Delete
    End With
    Range("A1").AutoFilter
End Sub


MUMPS! you've helped me twice now with the same project in as many days. my hero! *swoon*
 
Upvote 0
There are other ways to delete rows, In addition to fixing your macro.
Here is another approach to delete lines :):

VBA Code:
Sub DeleteRows_2()
  With ActiveSheet
      .Columns("D").Replace what:="*shipped*", replacement:="#N/A", Lookat:=xlWhole
      On Error Resume Next
      .UsedRange.SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
  End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

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