Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2011, 11:28 PM
atilla atilla is offline Removing secondary entries Windows 7 64bit Removing secondary entries Office 2010 32bit
Novice
Removing secondary entries
 
Join Date: Jul 2011
Posts: 3
atilla is on a distinguished road
Default Removing secondary entries

Hi Folks
Not the greatest expert on VBA/macro's so all assistance greatly welcomed.

I have a list consisting of events, the columns are:
Date, time, location, name.

This list can be dated anywhere between a couple of days and several weeks long.
Each user may appear several times on each date.

What i need to do is condense the list down is to show each user only once for each date. Additionally this is to be restricted to between certain hours. eg. 18:30 to 07:00.

Any suggestions and advice would be much appreciated.


Sample file attached.
Attached Files
File Type: xlsx door sample.xlsx (354.5 KB, 19 views)
Reply With Quote
  #2  
Old 07-15-2011, 09:34 PM
macropod's Avatar
macropod macropod is offline Removing secondary entries Windows 7 64bit Removing secondary entries Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,360
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Note: As coded, the macro -
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
Reply With Quote
  #3  
Old 07-16-2011, 04:27 PM
atilla atilla is offline Removing secondary entries Windows 7 64bit Removing secondary entries Office 2010 32bit
Novice
Removing secondary entries
 
Join Date: Jul 2011
Posts: 3
atilla is on a distinguished road
Default

@ macropod

Thank for the above assistance, it is much appreciated. Unfortunately i'm looking to find the entries before tam and after 6pm.
Playing about with the times and/or the <> operators to achieve correct results just returns a blank sheet. Any further pointers that may help?
Reply With Quote
  #4  
Old 07-16-2011, 07:17 PM
macropod's Avatar
macropod macropod is offline Removing secondary entries Windows 7 64bit Removing secondary entries Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,360
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi atilla,

Try replacing:
Code:
    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
with:
Code:
    If CDate(.Range("B" & i).Value) > CDate("7:00:00") Then
      If CDate(.Range("B" & i).Value) < CDate("18:00:00") Then
        .Range("A" & i).EntireRow.Delete
      End If
    End If
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-17-2011, 07:29 AM
atilla atilla is offline Removing secondary entries Windows 7 64bit Removing secondary entries Office 2010 32bit
Novice
Removing secondary entries
 
Join Date: Jul 2011
Posts: 3
atilla is on a distinguished road
Default

@ macropod
Sir, you are a star.
Many thanks for kind help.

I'm going to have to start learning this stuff me thinks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Custom XML Ulodesk Word 0 06-24-2011 09:01 AM
Removing secondary entries 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft