Automatically update a cell with last modified date and time

Solved/Closed
NazCarr Posts 12 Registration date Monday 25 March 2019 Status Member Last seen 26 January 2021 - 13 May 2019 à 06:06
NazCarr Posts 12 Registration date Monday 25 March 2019 Status Member Last seen 26 January 2021 - 16 May 2019 à 08:01
I am maintaining a Test Environment Catalogue, with various users editing it. It is change controlled in SharePoint, however, I'd like to insert a cell labelled "Last Updated" - and the cell should reflect the last date and time the excel sheet was edited. (Only edited... not viewed... )

Columns B:K have content that could be edited
I have added a row with cell A1: Last Updated
And B1: <Cell that will contain dd/mm/yy hh:mm>

I have tried to create a module:

Public Function ModDate()

ModDate = Format(FileDateTime(ThisWorkbook.FullName), "dd/mm/yy hh:n ampm")

End Function

But this does not work

And I tried:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("C:k"), Target)
xOffsetColumn = 1
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 = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub


But could not quite understand how to modify this code for my sheet....

Any help from your end would be greatly appreciated....

Many Thanks,
Naz
Related:

1 response

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
14 May 2019 à 12:04
Hi Naz,

Give the following code a try:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("B2:K" & Rows.Count), Target) Is Nothing Then Exit Sub
Range("B1").Value = Now
End Sub


To change the date format, if necessary, go to the cell properties (Ctrl+1).

Best regards,
Trowa
NazCarr Posts 12 Registration date Monday 25 March 2019 Status Member Last seen 26 January 2021
16 May 2019 à 08:01
Works! Perfect solution. Thanks TrowaD - again!