![]() |
|
#2
|
||||
|
||||
|
Hi atilla,
Try the following macro: Code:
Sub Cleanup()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim i As Long, LastRow As Long
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
For i = LastRow To 2 Step -1
If CDate(.Range("B" & i).Value) < CDate("7:00:00") Then
.Range("A" & i).EntireRow.Delete
End If
If CDate(.Range("B" & i).Value) > CDate("18:00:00") Then
.Range("A" & i).EntireRow.Delete
End If
Next
LastRow = .Range("A" & .Cells.SpecialCells(xlCellTypeLastCell).Row).End(xlUp).Row
With .Sort
With .SortFields
.Clear
.Add Key:=Range("A1:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.Add Key:=Range("D1:D" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("B1:B" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
.SetRange Range("A1:D" & LastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For i = LastRow To 2 Step -1
If .Range("A" & i).Value & .Range("D" & i).Value = .Range("A" & i - 1).Value & .Range("D" & i - 1).Value Then
.Range("A" & i).EntireRow.Delete
End If
Next
End With
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
1. deletes entries before 7AM and after 6PM. Modify the '7:00:00' and '18:00:00' to suit your needs. 2. preserves only the earliest valid entry for users with multiple entries on the same date. To keep only the last valid entry, change the last instance of 'xlAscending' to 'xlDescending'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 07-15-2011 at 10:14 PM. Reason: Note Revision |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing Custom XML | Ulodesk | Word | 0 | 06-24-2011 09:01 AM |
Sent foder in secondary email account
|
zoran32 | Outlook | 1 | 04-25-2011 03:29 PM |
| Secondary IP address Outlook Fail-over | danish.mustafa | Outlook | 0 | 03-01-2010 01:32 AM |
| Removing All Formating | basscarp | Word | 0 | 01-31-2010 05:49 PM |
| Applying And Removing Letterhead | skoz55 | Word | 0 | 08-06-2009 10:22 PM |