Macro for start and end timestamp when cells are completed

phillip87

Board Regular
Joined
Jan 28, 2019
Messages
69
Hi, I have the below macro running in a different worksheet which works great however it only provides a timestamp when the first cell is changed.

however we currently have someone doing data entry and I would like to add a second timestamp "finish" for the last cell changed (AA:AA & -2) in order to help verify their time sheet hours, I am sure this is a very easy solution that I am just not seeing.

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("D:D"), Target)
xOffsetColumn = -3
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If I understand you correctly, one simple way is to just add a second block of code, similar to your first, like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722

'   Check first range (column D)
    Dim WorkRng As Range
    Dim Rng As Range
    Dim xOffsetColumn As Integer
    
    Set WorkRng = Intersect(Application.ActiveSheet.Range("D:D"), Target)
    xOffsetColumn = -3

    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
        For Each Rng In WorkRng
            If Not VBA.IsEmpty(Rng.Value) Then
                Rng.Offset(0, xOffsetColumn).Value = Now
                Rng.Offset(0, xOffsetColumn).NumberFormat = "hh:mm:ss"
            Else
                Rng.Offset(0, xOffsetColumn).ClearContents
            End If
        Next
        Application.EnableEvents = True
    End If
    
'   Check second range (column AA)
    Dim WorkRng2 As Range
    Dim Rng2 As Range
    Dim xOffsetColumn2 As Integer
    
    Set WorkRng2 = Intersect(Application.ActiveSheet.Range("AA:AA"), Target)
    xOffsetColumn2 = -2

    If Not WorkRng2 Is Nothing Then
        Application.EnableEvents = False
        For Each Rng2 In WorkRng2
            If Not VBA.IsEmpty(Rng2.Value) Then
                Rng2.Offset(0, xOffsetColumn2).Value = Now
                Rng2.Offset(0, xOffsetColumn2).NumberFormat = "hh:mm:ss"
            Else
                Rng2.Offset(0, xOffsetColumn2).ClearContents
            End If
        Next
        Application.EnableEvents = True
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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