Vba/Macro help with a Time sheet which draws from raw data from separate sheet

CliffWeb

New Member
Joined
Aug 15, 2016
Messages
23
I need help with a Timesheet which draws info from raw data on sheet 2 (using Macro/VBA)
The system is shows a log in per skill, there are duplicates of the same log in. They should be viewed as one log in.
There should be 3 breaks in this order 1break (15mins) 2nd break lunch (30mins) 3rd. break (15mins). There can more than 3 breaks, I need a column or row created for each break total
Some reps work past midnight say 2am the link includes the excel worksheet example https://app.box.com/s/x8xm1ezhatsxhz6myze7q1h6ev8yvih7


Sheet 1 has the info I need
Rep Name
Date
Total Hours Worked
Total Break Time
1st log in
Last log out
Total # of breaks taken
1st break total
2nd Break total
3rd break total and so on and so on.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I got this answered in another post, I'm reposting for anyone who could use it.

Sub MG17Aug19
Dim Dn As Range, temp As String
Dim Rng As Range, Dic As Object, Bk As String
Dim Q As Variant, n As Long, P As Variant
Dim ray(), Temp2 As String
Dim k As Variant, c As Long, Num As Integer
Dim R As Long, Tb As Double, oMax As Long
With Sheets("Sheet2")
Set Rng = .Range(.Range("B4"), .Range("B" & Rows.Count).End(xlUp))
End With
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
For Each Dn In Rng
temp = IIf(Dn.Offset(, -1).Value = "", temp, Dn.Offset(, -1).Value)
If Dn.Offset(, 2) <> Temp2 Then
If Not Dic.exists(temp) Then
Set Dic(temp) = CreateObject("Scripting.Dictionary")
End If
If Len(Dn.Value) Then
If Not Dic(temp).exists(Dn.Value) Then
ReDim ray(1 To Rng.Count)
Dic(temp).Add (Dn.Value), Array(ray, Dn.Offset(, 2), 1, "")
Else
Q = Dic(temp).Item(Dn.Value)
Q(0)(Q(2)) = Dn.Offset(, 2) - Dn.Offset(-1, 3)
Q(2) = Q(2) + 1
Q(3) = Dn.Offset(, 3)
Dic(temp).Item(Dn.Value) = Q
End If
Temp2 = Dn.Offset(, 2)
End If
End If

Next Dn

c = 1
For Each k In Dic.Keys
With Sheets("Sheet1")
.Cells(1, 1).Resize(, 7) = Array("Rep Name", "Date", "Total Hours Worked", "Total Break Time", "1st log in", "Last log out", "Total number of breaks")
For Each P In Dic(k)
c = c + 1
.Cells(c, "A") = k
.Cells(c, "B") = P
.Cells(c, "C") = Format(Dic(k).Item(P)(3) - Dic(k).Item(P)(1), "h:mm")
.Cells(c, "E") = Format(Dic(k).Item(P)(1), "h:mmAM/PM")
.Cells(c, "F") = Format(Dic(k).Item(P)(3), "h:mmAM/PM")

For R = 1 To UBound(Dic(k).Item(P)(0))
If Len(Dic(k).Item(P)(0)(R)) Then
Num = Num + 1: oMax = Application.Max(oMax, Num)
.Cells(1, "G").Offset(, Num) = "Break (" & Num & ")"
.Cells(c, "G").Offset(, Num) = Format(Dic(k).Item(P)(0)(R) * 24 * 60, "0") & " Mins"
Tb = Tb + Dic(k).Item(P)(0)(R)
End If
Next R
.Cells(c, "D") = Tb * 24 * 60 & " Mins"
.Cells(c, "G") = Num: Num = 0
Tb = 0
Next P
End With
Next k

With Sheets("Sheet1").Cells(1, 1)
With .Resize(c, oMax + 7)
.Borders.Weight = 2
.Columns.AutoFit
End With
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,914
Messages
6,175,351
Members
452,638
Latest member
Oluwabukunmi

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