filter and delete rows based on two criteria

  • Thread starter Arnold Klapheck
  • Start date
A

Arnold Klapheck

I have a large spreadsheet and in it I have a from and through date column in
G and H I want to delete rows before date of "FromDate" and after date of
"ThruDate

I started with a subroutine of:

Sub old()

Sheets("DR-6 Data (As Shipper)").Select

' Removes Data Prior To The Audit Period.
Range("A2").Select
Do Until ActiveCell.Offset([0], [0]) = ""
If ActiveCell.Offset([0], [7]) < FromDate Then
Selection.EntireRow.Delete
Else: ActiveCell.Offset([1], [0]).Select
End If
Loop

' Removes Data After The Audit Period.
Range("A2").Select
Do Until ActiveCell.Offset([0], [0]) = ""
If ActiveCell.Offset([0], [6]) > ThruDate Then
Selection.EntireRow.Delete
Else: ActiveCell.Offset([1], [0]).Select
End If
Loop
Range("A2").Select
End Sub 'Old

I saw Ron De Bruin answered a similar question and modified his code but
still need some help

Sub Delete_with_Autofilter_Two_Criteria()

Dim rng As Range
Sheets("DR-6 Data (As Shipper)").Select

With ActiveSheet
.Range("A2").Select.AutoFilter Field:=1, Criteria1:=FromDate, _
Operator:=xlOr, Criteria2:=ThruDate 'getting error code here
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub

Hopefully Someone can help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top