0

I have the following code in a module for a date and time stamp but when I open the spreadsheet each day, the spreadsheet is restamping and putting the present date and time from today instead of yesterday. Does anyone know if I'm missing something in the code to stop the spreadsheet from doing this as I need to retain the stamps from when they happened? Thanks in advance.

    If Reference.Value <> "" Then
        Datestamp1 = Format(Now, "dd/mm/yyyy HH:mm")
    Else
        Datestamp1 = ""
    End If

    Application.EnableEvents = False

End Function
Miles Fett
  • 711
  • 4
  • 17
rwc14
  • 11
  • 5
  • I assume the output is in a cell. If this is the case simply set the value of the cell with the value of the time stamp so it does not update with the `Now` logic. You can then set a trigger for when you want to define it to update. – Dean Sep 18 '19 at 08:46
  • `If Len(Trim(rng.Value)) = 0 Then rng.Value = Format(Now, "dd/mm/yyyy HH:mm")` Insert the time stamp only if the cell where you want to put the timestamp is empty. – Siddharth Rout Sep 18 '19 at 08:53
  • 1
    Your code checks if `Reference` **is not** empty. If true, then it will calculate `Datestamp1`. If false, it will empty variable `Datestamp1`. IS that right? Shouldn't it be `If Reference.Value = ""`? – Foxfire And Burns And Burns Sep 18 '19 at 08:54
  • Sorry if I wasn't clear: forgot to add that I have =Datstamp1(S2) in the T column so that if anything is entered in the S cells then a time stamp appears in T. – rwc14 Sep 18 '19 at 09:05
  • Then do not handle it using formulas. Use Worksheet_Change Event – Siddharth Rout Sep 18 '19 at 11:31

0 Answers0