Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I delete rows programmatically based on certain criteria? nt_artagnian[_2_] New Users to Excel 2 March 8th 07 03:56 AM
Delete rows based on criteria Chris_t_2k5 Excel Discussion (Misc queries) 2 April 11th 06 01:52 PM
Delete rows based on certain criteria Coal Miner Excel Discussion (Misc queries) 2 March 3rd 06 05:56 PM
Auto Filter Delete Rows by Criteria Doesn't Work Range To Complicated robertjtucker[_8_] Excel Programming 1 September 29th 05 05:47 PM
I want to delete certain rows based on specific criteria Alaphas Excel Programming 2 May 18th 05 11:06 PM


All times are GMT +1. The time now is 06:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"