Auto Update Timestamp resets everytime opening the file

shirazx3

New Member
Joined
Jul 7, 2022
Messages
23
Office Version
  1. 2021
Platform
  1. Web
Hello,
I am trying to create an instance where a value entered in A1 gives a timestamp to in B1 and everytime A1 is updated, it updates the timestamp in B1. I was able to achieve it using macros but the issue I am facing is that everytime I open the file, all the timestamps are set to the time the file is opened.
Book1
AB
1LOGIN DAYLOGIN DATE/TIME
217/14/22 17:20
327/14/22 17:20
437/14/22 17:20
547/14/22 17:20
6 
7 
8 
9 
10 
11 
12 
13 
14 
Sheet1
Cell Formulas
RangeFormula
B2:B14B2=MyTimestamp(A2)


VBA Code:
Function MyTimestamp(Reference As Range)

If Reference.Value <> "" Then

MyTimestamp = Format(Now, "m/d/yy hh:mm")

Else

MyTimestamp = ""

End If

End Function
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If you use a volatile formula, it changes automatically.
Since you are using VBA, you can use the worksheet_Change event.

Right click the sheet tab and select "View Code"
Paste this code there.
Enter something in A2:A10 and see what happens.Change target range as requiered

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub    ' this stops code error if more than one cell is changed at once

    If Not Application.Intersect(Target, Me.Range("A2:A10")) Is Nothing Then    ' indicates the Target range
       Target.Offset(, 1) = Format(Now, "m/d/yy hh:mm")
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,231
Messages
6,123,754
Members
449,119
Latest member
moudenourd

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