ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   filter and delete rows based on two criteria (https://www.excelbanter.com/excel-programming/371990-filter-delete-rows-based-two-criteria.html)

Arnold Klapheck

filter and delete rows based on two criteria
 
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?


All times are GMT +1. The time now is 09:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com