Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How can I delete rows programmatically based on certain criteria? | New Users to Excel | |||
Delete rows based on criteria | Excel Discussion (Misc queries) | |||
Delete rows based on certain criteria | Excel Discussion (Misc queries) | |||
Auto Filter Delete Rows by Criteria Doesn't Work Range To Complicated | Excel Programming | |||
I want to delete certain rows based on specific criteria | Excel Programming |