Delete Rows whose value is not between 2 dates
One way:
Enter the Start Date in F1 and Finish Date in G1
Then run this macro
Sub DeleteDates()
Dim StDate As Date, FinDate As Date
Dim LastRow As Integer
StDate = Range("F1").Value
FinDate = Range("G1").Value
LastRow = Cells(Rows.Count, 5).End(xlUp).Row
For I = 2 To LastRow
If Cells(I, 5).Value = StDate And Cells(I, 5).Value <= FinDate Then
Cells(I, 8).Value = "D"
End If
Next
Range("H1").Select
'Note Field:=8 assumes columns A-D have data, otherwise Field could = 4
Selection.AutoFilter Field:=8, Criteria1:="D"
Range("A2:H" & LastRow).Select
Selection.Delete
Selection.AutoFilter
Range("A1").Select
End Sub
Glen
"Dominique Feteau" wrote in message
...
I have a report that is imported into excel. I dont need all the data.
Column E has dates. I'd like to delete the rows that arent between 2
dates.
for example, when the macro is run, it'll ask me for a beginning date and
a
ending date and delete all the rows that dont equal.
any suggestions?
|