FIRST and the LAST time readings from the daily card readings and ignoring the ones in between

pulsarkuant

New Member
Joined
Jan 9, 2011
Messages
20
We are using the attached excel to log Staff START and end times. We have logs from the card readers and basically copying the raw logs to the "Raw Data" sheet and hitting the CommadnButton to distribute to the staff listed in the "Personel" sheet. It works fine, but I want to only pick the very FIRST and the LAST reading during each day and ignore any readings in between. How can I tell the below code to pick the first and the last reading?

##The command button on the "Raw Data" sheet has the below VB code and attached an image.

VBA Code:
Private Sub CommandButton1_Click()

Dim irow As Long
 
 Application.ScreenUpdating = False
 With ActiveSheet
    For irow = .Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
        If UCase(.Cells(irow, 2)) Like "*ADMINDOOR*" Or _
            UCase(.Cells(irow, 2)) Like "*LIFT*" Or _
            UCase(.Cells(irow, 2)) Like "*CANTEEN*" Or _
             UCase(.Cells(irow, 2)) Like "*GATE*" Then
            .Rows(irow).Delete
        End If
    Next
 End With
 Application.ScreenUpdating = True

 
For a = 3 To Sheets("Personel").Cells(65000, 1).End(xlUp).Row
For b = 1 To Sheets("Raw data").Cells(65000, 1).End(xlUp).Row
 c = Len(Sheets("Personel").Cells(a, 1))
 If Left(Cells(b, 2), c) = Sheets("Personel").Cells(a, 1) Then
 d = Day(Cells(b, 1)) * 2
 If Hour(Cells(b, 1)) > 11 Then d = d + 1
Sheets("Personel").Cells(a, d + 1) = Hour(Cells(b, 1)) & ":" & Minute(Cells(b, 1))
End If
Next
Next

End Sub


##Minisheet shows the raw data to process

FEBRUARY_2022 Staff Attendance Report.xlsm
AB
217/02/2022 6:43John Brown Card Access at <R41:Rdr03> into B7Door [Card 546888]
317/02/2022 6:43IB L3 Staff RoomB Locked by (Door Logic) (D042)
417/02/2022 6:43IB L3 Staff RoomB Timed Unlocked for 00 h 00 min 05 s by R25: AdminBuilding L2 Comms Room (Door Logic) (D042)
517/02/2022 6:43Elizabeth Scott Card Access at <R25:Rdr01> into IB L3 Staff RoomB [Card 546599]
617/02/2022 6:42Elizabeth Scott Card Access at <R32:Rdr01> into AdminBuilding SW B [Card 546599]
717/02/2022 6:42IB L1 S Auto Door + PIN Locked by (Door Logic) (D016)
817/02/2022 6:42IB L1 S Auto Door + PIN Timed Unlocked for 00 h 00 min 05 s by R12: AdminBuilding L2 Comms Room (Door Logic) (D016)
917/02/2022 6:42Elizabeth Scott Card Access at <R12:Rdr01> into IB L1 S Auto Door + PIN [Card 546599]
1017/02/2022 6:40E1 Timed Unlocked for 00 h 00 min 05 s by R46: E Block (Door Logic) (D073)
1117/02/2022 6:40Abraham Parry Card Access at <R46:Rdr03> into E1Door [Card 658215]
1217/02/2022 13:43John Brown Card Access at <R41:Rdr03> into B7Door [Card 546888]
1317/02/2022 14:44Elizabeth Scott Card Access at <R12:Rdr01> into IB L1 S Auto Door + PIN [Card 546599]
1417/02/2022 14:45Abraham Parry Card Access at <R46:Rdr03> into E1Door [Card 658215]
1517/02/2022 16:43John Brown Card Access at <R41:Rdr03> into B7Door [Card 546888]
1617/02/2022 16:44Elizabeth Scott Card Access at <R12:Rdr01> into IB L1 S Auto Door + PIN [Card 546599]
1717/02/2022 16:45Abraham Parry Card Access at <R46:Rdr03> into E1Door [Card 658215]
1815/02/2022 7:55John Brown Card Access at <R41:Rdr03> into B7Door [Card 546888]
1915/02/2022 7:55IB L3 Staff RoomB Locked by (Door Logic) (D042)
2015/02/2022 7:55IB L3 Staff RoomB Timed Unlocked for 00 h 00 min 05 s by R25: AdminBuilding L2 Comms Room (Door Logic) (D042)
2115/02/2022 7:55Elizabeth Scott Card Access at <R25:Rdr01> into IB L3 Staff RoomB [Card 546599]
2215/02/2022 11:40Elizabeth Scott Card Access at <R32:Rdr01> into AdminBuilding SW B [Card 546599]
2315/02/2022 11:40IB L1 S Auto Door + PIN Locked by (Door Logic) (D016)
2415/02/2022 11:40IB L1 S Auto Door + PIN Timed Unlocked for 00 h 00 min 05 s by R12: AdminBuilding L2 Comms Room (Door Logic) (D016)
2515/02/2022 11:40Elizabeth Scott Card Access at <R12:Rdr01> into IB L1 S Auto Door + PIN [Card 546599]
2615/02/2022 11:40E1 Timed Unlocked for 00 h 00 min 05 s by R46: E Block (Door Logic) (D073)
2715/02/2022 11:40Abraham Parry Card Access at <R46:Rdr03> into E1Door [Card 658215]
2815/02/2022 11:40John Brown Card Access at <R41:Rdr03> into B7Door [Card 546888]
2915/02/2022 16:12Elizabeth Scott Card Access at <R12:Rdr01> into IBr + PIN [Card 546599]
3015/02/2022 16:11Abraham Parry Card Access at <R46:Rdr03> into E1Door [Card 658215]
3115/02/2022 16:11John Brown Card Access at <R41:Rdr03> into B7Door [Card 546888]
3215/02/2022 16:11Elizabeth Scott Card Access at <R12:Rdr01> into IB L1 S Auto Door + PIN [Card 546599]
3315/02/2022 16:11Abraham Parry Card Access at <R46:Rdr03> into E1Door [Card 658215]
Raw data



##The below shows the end result in the second sheet called "Personel"

FEBRUARY_2022 Staff Attendance Report.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKAL
1TUEWEDTHUFRISATSUNMONTUEWEDTHUFRISATSUNMONTUEWEDTHUFRI
2112233445566778899101011111212131314141515161617171818
3John Brown11:4016:116:4316:43
4Elizabeth Scott11:4016:116:4216:44
5Abraham Parry11:4016:116:4016:45
6
7
Personel
 

Attachments

  • Explaination.jpg
    Explaination.jpg
    169.8 KB · Views: 4

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
suppose Bill Gates is working in your firm, then you get in problems with those "forbidden" words, like "gate".
Work around, check for those words after the 15th character with
b = (InStr(1, a(i, 2), strg, vbTextCompare) > 15)
VBA Code:
          For i = UBound(a) To 2 Step -1                        'loop from last row upwards
               For Each strg In Array("admindoor", "lift", "Canteen", "gate")     'list of specific term not to be used
                    b = (InStr(1, a(i, 2), strg, vbTextCompare) > 15)    'is that term in that cell = skip that row, don't look in the 1st 15 characters
                    If b Then Exit For
               Next
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top