MARCO VBA: Auto rec which cell is last modified (Code only rec time/date/userid)

harky

Active Member
Joined
Apr 8, 2010
Messages
405
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hi,

I had a code which auto update time & date on Col E
and last modified userid on col F.

Possible to rec which is the last modified cell?

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD]abc[/TD]
[TD]def[/TD]
[TD]ghi[/TD]
[TD]jkl[/TD]
[TD]8/9/2019 5:03:51 PM[/TD]
[TD]C:\Users\TOM , update Cell A, B, C,D[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Code to put the date of the latest update following a change in the corresponding cell in column F
    Dim WorkRng As Range, roww As Long
    Dim rng As Range
    Set WorkRng = Intersect(Range("A:D"), Target)
    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
            For Each rng In WorkRng
                roww = rng.Row
                If Not rng.Value = "" Then
                    Cells(roww, "E").Value = Now
                    Cells(roww, "E").NumberFormat = "dd-mm-yyyy, hh:mm:ss"
                    Cells(roww, "F").Value = Environ$("Userprofile")
                Else
                    Cells(roww, "E").ClearContents
                    Cells(roww, "F").ClearContents
                End If
            Next
        Application.EnableEvents = True
    End If
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Perhaps by changing this line
Code:
Cells(roww, "F").Value = Environ$("Userprofile") [COLOR="#FF0000"]&", update Cell" & Target.Address(0, 0)[/COLOR]
 
Upvote 0
Another option
Code:
                If Not Rng.Value = "" Then
                    Cells(roww, "E").Value = Now
                    Cells(roww, "E").NumberFormat = "dd-mm-yyyy, hh:mm:ss"
                    If Cells(roww, "F").Value = "" Then
                        Cells(roww, "F").Value = Environ$("Userprofile") & ", update Cell" & Rng.Address(0, 0)
                     Else
                        Cells(roww, "F").Value = Cells(roww, "F").Value & ", " & Rng.Address(0, 0)
                     End If
                Else
                    Cells(roww, "E").ClearContents
                    Cells(roww, "F").ClearContents
                End If
 
Upvote 0
Thanks. this only display 1 cell...

Perhaps by changing this line
Code:
Cells(roww, "F").Value = Environ$("Userprofile") [COLOR=#FF0000]&", update Cell" & Target.Address(0, 0)[/COLOR]
 
Upvote 0
Thanks!!!!!!! quite close.. i think my way of tracking rec got it wrong.
i cant use it this way. LOL
The cell forever fill...... :P

[TABLE="width: 402"]
<tbody>[TR]
[TD="class: xl63, width: 402"]C:\Users\TOM, update Cell A2, B2, C2, D2, D2, D2, D2 :)[/TD]
[/TR]
</tbody>[/TABLE]

Another option
Code:
                If Not Rng.Value = "" Then
                    Cells(roww, "E").Value = Now
                    Cells(roww, "E").NumberFormat = "dd-mm-yyyy, hh:mm:ss"
                    If Cells(roww, "F").Value = "" Then
                        Cells(roww, "F").Value = Environ$("Userprofile") & ", update Cell" & Rng.Address(0, 0)
                     Else
                        Cells(roww, "F").Value = Cells(roww, "F").Value & ", " & Rng.Address(0, 0)
                     End If
                Else
                    Cells(roww, "E").ClearContents
                    Cells(roww, "F").ClearContents
                End If
 
Last edited:
Upvote 0
Maybe
Code:
                If Not Rng.Value = "" Then
                    Cells(roww, "E").Value = Now
                    Cells(roww, "E").NumberFormat = "dd-mm-yyyy, hh:mm:ss"
                    If Cells(roww, "F").Value = "" Then
                        Cells(roww, "F").Value = Environ$("Userprofile") & ", update Cell" & Rng.Address(0, 0)
                     ElseIf InStr(1, Cells(roww, "F").Value, Rng.Address(0, 0)) = 0 Then
                        Cells(roww, "F").Value = Cells(roww, "F").Value & ", " & Rng.Address(0, 0)
                     End If
                Else
                    Cells(roww, "E").ClearContents
                    Cells(roww, "F").ClearContents
                End If
 
Upvote 0
ah this work great. Thanks bro!

Maybe
Code:
                If Not Rng.Value = "" Then
                    Cells(roww, "E").Value = Now
                    Cells(roww, "E").NumberFormat = "dd-mm-yyyy, hh:mm:ss"
                    If Cells(roww, "F").Value = "" Then
                        Cells(roww, "F").Value = Environ$("Userprofile") & ", update Cell" & Rng.Address(0, 0)
                     ElseIf InStr(1, Cells(roww, "F").Value, Rng.Address(0, 0)) = 0 Then
                        Cells(roww, "F").Value = Cells(roww, "F").Value & ", " & Rng.Address(0, 0)
                     End If
                Else
                    Cells(roww, "E").ClearContents
                    Cells(roww, "F").ClearContents
                End If
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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