Created
April 15, 2017 02:30
-
-
Save cwilper/874d051e2b84f56f54a2e766145e5cb3 to your computer and use it in GitHub Desktop.
Excel VBA code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'If G and H are defined for the given row, add the difference to K and clear them | |
Private Sub Update_Total(ByVal Row As Integer) | |
Dim punchStart, punchEnd, timeWorked As Integer | |
punchStart = Range("G" & Row).Value | |
punchEnd = Range("H" & Row).Value | |
timeWorked = punchEnd - punchStart | |
If (punchStart > 0 And punchEnd > 0 And timeWorked > 0) Then | |
Range("K" & Row).Value = Range("K" & Row) + timeWorked | |
Range("G" & Row).Value = "" | |
Range("H" & Row).Value = "" | |
End If | |
End Sub | |
'Anytime a value in column 6 (F) changes, call Update_Total for that row | |
Private Sub Worksheet_Change(ByVal Target As Range) | |
If (Target.Column = 6) Then | |
Update_Total (Target.Row) | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment