[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Automatically Moving Time Punch Data

I have a report that is exported from a time-clock program and I need to re-align the punch times.  The attached workbook has the data table with what are 3 typical variations of punches I see.

Lines 4 and 5:  These are standard daily punches, the punches occur on the same date the first line is the morning, the second line is after lunch.  On this one I need to move the second set of punches (in red text) to the end of the previous line (dark blue boxes)

Line 17: This punch is when someone forgets to punch out for lunch/break or works less than 5 hours.  For this punch I need to move that end of day punch (green text) to the end of that line (green box)

Lines 21 and 22:  This set of punches are for our graveyard shift and the first punch in is usually between 10:00pm and 11:59pm on one day (noted in black bold, 10/19/2013) and the remaining punches for that shift are actually the next day (noted in blue bold, 10/20/2013).  I need to move the second set of punches (brown text) to the end of the previous line (dark purple boxes)

Thank you,
Edwin
Punch-Extract-Report-2013-10-24.xls
0
gixxer1020
Asked:
gixxer1020
  • 5
  • 5
1 Solution
 
byundtCommented:
You didn't say whether you wanted a formula or a macro.

Here is a formula for cell H6 that may be copied down:
=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),F6=H5),F6=""),"",
IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),F7,""))

Here is a formula for cell I6 that may be copied down:
=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),G6=I5),G6=""),"",
IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),G7,IF(G6-F6>5/24,G6,"")))

The equivalent macro is:
Sub PunchCardReporter()
Dim rg As Range
With Worksheets("Sheet1")
    Set rg = .Range("E6")    'First Date
    Set rg = Range(rg, .Cells(.Rows.Count, rg.Column).End(xlUp)).EntireRow    'All the data
End With
rg.Cells(1, "H").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),F6=H5),F6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),F7,""""))"
rg.Cells(1, "I").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),G6=I5),G6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),G7,IF(G6-F6>5/24,G6,"""")))"
rg.Columns("H").FillDown
rg.Columns("I").FillDown
rg.Columns("H").Formula = rg.Columns("H").Value
rg.Columns("I").Formula = rg.Columns("I").Value
End Sub

Open in new window


If you want to delete the rows where you moved data, I suggest AutoFilter on column I looking for empty strings (="") which look like blanks. Those rows can be deleted.
Punch-Extract-Report-2013-10-24Q.xls
0
 
gixxer1020Author Commented:
Thanks byundt,

Works great...can you move the data instead of copying it?

Thanks,
Edwin
0
 
gixxer1020Author Commented:
Oh, and I'll be using the Macro

Thanks,
Edwin
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
byundtCommented:
Edwin,
I'd be glad to edit the macro to suit your needs.

Could you please post a file with a worksheet showing what the results ought to look like after the macro has run on your sample data? I ask because I'm not understanding why you would want to move the contents of F7:G7 into H6:I6 while leaving the rest of row 7 alone.

Brad
0
 
gixxer1020Author Commented:
Thanks Brad,

File attached.
Table below the original is the end result I'm going for...the sorting and elimination of extra rows i can do, its the code you wrote I had no idea of how to do

Thanks,
Edwin
Punch-Extract-Report-2013-10-24-.xls
0
 
byundtCommented:
Edwin,
Here is the revised macro. I modified the formula for cell I6 to allow for the possibility that a person might work until the following day, but not do the punch out/in for their lunch break. This affects line 20. I also added code to delete the rows where data had been copied from.
Sub PunchCardReporter()
Dim rg As Range
Dim i As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
    Set rg = .Range("E6")    'First Date
    Set rg = Range(rg, .Cells(.Rows.Count, rg.Column).End(xlUp)).EntireRow    'All the data
End With
rg.Cells(1, "H").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),F6=H5),F6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),F7,""""))"
rg.Cells(1, "I").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),G6=I5),G6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),G7,IF(MOD(G6-F6,1)>5/24,G6,"""")))"
rg.Columns("H").FillDown
rg.Columns("I").FillDown
rg.Columns("H").Formula = rg.Columns("H").Value
rg.Columns("I").Formula = rg.Columns("I").Value
For i = rg.Rows.Count To 1 Step -1
    If rg.Cells(i, "I").Value = "" Then rg.Rows(i).EntireRow.Delete
Next
End Sub

Open in new window

Brad
Punch-Extract-Report-2013-10-24Q.xls
0
 
byundtCommented:
One more revision needed to the macro to handle the possibility that a person worked graveyard shift and went home before working 5 hours. Such a row should not be deleted even though columns H and I are blank.
Sub PunchCardReporter()
Dim rg As Range
Dim i As Long
Application.ScreenUpdating = False
With Worksheets("Sheet2")
    Set rg = .Range("E6")    'First Date
    Set rg = Range(rg, .Cells(.Rows.Count, rg.Column).End(xlUp)).EntireRow    'All the data
End With
rg.Cells(1, "H").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),F6=H5),F6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),F7,""""))"
rg.Cells(1, "I").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),G6=I5),G6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),G7,IF(MOD(G6-F6,1)>5/24,G6,"""")))"
rg.Columns("H").FillDown
rg.Columns("I").FillDown
rg.Columns("H").Formula = rg.Columns("H").Value
rg.Columns("I").Formula = rg.Columns("I").Value
For i = rg.Rows.Count To 1 Step -1
    If (rg.Cells(i, "I").Value = "") And _
        (rg.Cells(i, "F").Value = rg.Cells(i - 1, "H").Value) And (rg.Cells(i, "G").Value = rg.Cells(i - 1, "I").Value) Then _
        rg.Rows(i).EntireRow.Delete
Next
End Sub

Open in new window

0
 
gixxer1020Author Commented:
One  last thing Brad,

On lines 17 and 21 the punches that you moved to the end were not deleted out of their original location.  Other than that the code is amazing

Thank you,
Edwin
0
 
byundtCommented:
Edwin,
I added an ElseIf section to handle the case of column G value being moved to column I.
Sub PunchCardReporter()
Dim rg As Range
Dim i As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
    Set rg = .Range("E6")    'First Date
    Set rg = Range(rg, .Cells(.Rows.Count, rg.Column).End(xlUp)).EntireRow    'All the data
End With
rg.Cells(1, "H").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),F6=H5),F6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),F7,""""))"
rg.Cells(1, "I").Formula = "=IF(OR(AND($C5=$C6,OR($E5=$E6,$E5=$E6-1),G6=I5),G6=""""),""""," & _
    "IF(AND($C6=$C7,OR(AND($E6=$E7,$G7>$F7),$G6<$F6)),G7,IF(MOD(G6-F6,1)>5/24,G6,"""")))"
rg.Columns("H").FillDown
rg.Columns("I").FillDown
rg.Columns("H").Formula = rg.Columns("H").Value
rg.Columns("I").Formula = rg.Columns("I").Value
For i = rg.Rows.Count To 1 Step -1
    If (rg.Cells(i, "I").Value = "") And _
        (rg.Cells(i, "F").Value = rg.Cells(i - 1, "H").Value) And (rg.Cells(i, "G").Value = rg.Cells(i - 1, "I").Value) Then
        rg.Rows(i).EntireRow.Delete
    ElseIf rg.Cells(i, "G").Value = rg.Cells(i, "I").Value Then
        rg.Cells(i, "G").ClearContents
    End If
Next
End Sub

Open in new window

Brad
Punch-Extract-Report-2013-10-24Q.xls
0
 
gixxer1020Author Commented:
Thanks Brad....works like a champ

Edwin
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now