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?

ABCDEF
abcdefghijkl8/9/2019 5:03:51 PMC:\Users\TOM , update Cell A, B, C,D

<tbody>
</tbody>


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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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

C:\Users\TOM, update Cell A2, B2, C2, D2, D2, D2, D2 :)

<tbody>
</tbody>

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,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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