Calculate an average entry time and exit time per day for each employee

liorchn

New Member
Joined
Jun 1, 2014
Messages
7
Hi,
Excel 2013.
I have a table containing employee attendance data every day (entry and exit). Each employee have a unique ID number, and also there may be multiple entrances and exits on any given day.
Ask for help in creating a table will be concentrated Average attendance of those employees ie, an average time of first entry, the mean final departure time and average working hours per day (net of course).
DATABASE:



EMP.NUMBEREMP.NAMEDATEENTRYLEAVEWORKING HOURS
1111JOHN01/01/201607:00:0017:00:0010:00:00
1111JOHN02/01/201607:10:0008:30:0001:20:00
1111JOHN02/01/201609:30:0016:30:0007:00:00
1111JOHN02/01/201617:30:0020:00:0002:30:00
1111JOHN03/01/201610:00:0018:00:0008:00:00
2222DANY01/01/201611:00:0014:30:0003:30:00
2222DANY01/01/201616:00:0018:00:0002:00:00
2222DANY02/01/201608:30:0018:00:0009:30:00
2222DANY03/01/201607:00:0012:00:0005:00:00
2222DANY03/01/201614:30:0020:30:0006:00:00
33PETER01/01/201608:00:0017:00:0009:00:00
33PETER02/01/201608:30:0016:30:0008:00:00
33PETER03/01/201609:00:0018:00:0009:00:00
33PETER18/01/201607:00:0011:00:0004:00:00
33PETER18/01/201614:00:0019:00:0005:00:00

<colgroup><col><col><col><col span="2"><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>

OUTPUT
EMP.NUMBEREMP.NAMEFIRST ENTRY
TIME-AVERAGE
LAST LEAVE
TIME - AVERAGE
DAILY WORKING
HOURS - AVERAGE
1111JOHN08:03:2018:20:0009:36:40
2222DANY08:50:0018:50:0008:40:00
33PETER08:07:3017:37:3008:45:00

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>


THX
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this, for results on sheet2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG01Jan46
[COLOR="Navy"]Dim[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range, Tot [COLOR="Navy"]As[/COLOR] Double, Q [COLOR="Navy"]As[/COLOR] Variant, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, k  [COLOR="Navy"]As[/COLOR] Variant, AvL [COLOR="Navy"]As[/COLOR] Double, AvH [COLOR="Navy"]As[/COLOR] Double
[COLOR="Navy"]Dim[/COLOR] Dic  [COLOR="Navy"]As[/COLOR] Object, p [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
 [COLOR="Navy"]Set[/COLOR] Dic = CreateObject("Scripting.Dictionary")
   Dic.CompareMode = 1
   [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
            [COLOR="Navy"]If[/COLOR] Not Dic.exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Set[/COLOR] Dic(Dn.Value) = CreateObject("Scripting.Dictionary")
            [COLOR="Navy"]End[/COLOR] If
        
        [COLOR="Navy"]If[/COLOR] Not Dic(Dn.Value).exists(Dn.Offset(, 2).Value) [COLOR="Navy"]Then[/COLOR]
                Dic(Dn.Value).Add (Dn.Offset(, 2).Value), _
                Array(Dn.Offset(, 3).Value, Dn.Offset(, 4).Value, Dn.Offset(, 5).Value, Dn)
        [COLOR="Navy"]Else[/COLOR]
                Q = Dic(Dn.Value).Item(Dn.Offset(, 2).Value)
                 [COLOR="Navy"]If[/COLOR] Dn.Offset(, 4).Value > Q(1) [COLOR="Navy"]Then[/COLOR] Q(1) = Dn.Offset(, 4).Value
                  [COLOR="Navy"]If[/COLOR] Dn.Offset(, 3).Value < Q(0) [COLOR="Navy"]Then[/COLOR] Q(0) = Dn.Offset(, 3).Value
                    Q(2) = Q(2) + Dn.Offset(, 5).Value
                Dic(Dn.Value).Item(Dn.Offset(, 2).Value) = Q
      
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] Dn
   
    ReDim ray(1 To Dic.Count + 1, 1 To 5)
    ray(1, 1) = "EMP.No": ray(1, 2) = "EMP.NAME"
     ray(1, 3) = "FIRST ENTRY" & vbLf & "TIME-AVERAGE"
       ray(1, 4) = "LAST LEAVE" & vbLf & " TIME-AVERAGE"
        ray(1, 5) = "DAILY WORKING" & vbLf & "HOURS-Average"
           c = 1
    
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] k [COLOR="Navy"]In[/COLOR] Dic.Keys
        c = c + 1
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] p [COLOR="Navy"]In[/COLOR] Dic(k)
           ray(c, 1) = k
             ray(c, 2) = Dic(k).Item(p)(3).Offset(, 1).Value
              AvL = AvL + Dic(k).Item(p)(0)
                AvH = AvH + Dic(k).Item(p)(1)
                 Tot = Tot + Dic(k).Item(p)(2)
             [COLOR="Navy"]Next[/COLOR] p
            
            ray(c, 3) = Format(AvL / Dic(k).Count, "hh:mm:ss")
              ray(c, 4) = Format(AvH / Dic(k).Count, "hh:mm:ss")
                ray(c, 5) = Format(Tot / Dic(k).Count, "hh:mm:ss")
                  Tot = 0: AvL = 0: AvH = 0
    [COLOR="Navy"]Next[/COLOR] k
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2").Range("A1").Resize(UBound(ray, 1), 5)
    .Value = ray
      .Borders.Weight = 2
       .Columns.AutoFit
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,203,224
Messages
6,054,234
Members
444,711
Latest member
Stupid Idiot

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