Finding First Check in Time

ravaz

Board Regular
Joined
Mar 25, 2008
Messages
196
Hi,

Am using the below code it picks the last check in time in the attendance data sheet:

Since there are multple check-ins by an employee how do I ensure I am picking the first checkin time
Code:
Sub Attendance()Dim a, b(), i As Long, ii As Long, n As Long, z As String
a = Sheets("Cons").Range("a2").CurrentRegion.Resize(, 10).Value
ReDim b(1 To UBound(a, 1), 1 To 31)
With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
        For i = 3 To UBound(a, 1)
            z = a(i, 2) '& ";" & a(i, 4)
            If Not .exists(z) Then
                n = n + 1: .Add z, n
                b(n, 1) = Trim(a(i, 2))
            End If
            If a(i, 4) = Cells(3, 2) Then
                b(.Item(z), 2) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 3) Then
                b(.Item(z), 3) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 4) Then
                b(.Item(z), 4) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 5) Then
                b(.Item(z), 5) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 6) Then
                b(.Item(z), 6) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 7) Then
                b(.Item(z), 7) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 8) Then
                b(.Item(z), 8) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 9) Then
                b(.Item(z), 9) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 10) Then
                b(.Item(z), 10) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 11) Then
                b(.Item(z), 11) = a(i, 5)
            ElseIf a(i, 4) = Cells(3, 12) Then
                b(.Item(z), 12) = a(i, 5)
            End If
        Next
End With
Sheets("Report").Range("a4:z100000").ClearContents
Sheets("Report").Range("a4").Resize(n, 12).Value = b
Sheets("Report").Range("a3:z100000").Sort Key1:=Range("a3"), Header:=xlYes, Order1:=xlAscending


End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Unrelated to your problem but you could change all those If Then ElseIfs to

Code:
zz=0
For zy=2 to 12
If a(i, 4) = cells(3, zy) Then
zz=zy
End If
Next zy
If zz<>0 Then
b(.item(z),zz)= a(i,5)
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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