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
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