3

I would like to know how to:

Automatically have the =now() function in the column B of Excel, only displayed in each cell (B1, B2, .. Bν) whenever I write something in column A in the respective cells (A1, A2, .. Aν).

enter image description here

Gareth
  • 18,809
stagml
  • 31
  • 1
    Do you really want to fill the function =Now(), so it'll always show the current date; our you want to create a "timestamp" to know when data in the cell was entered? – Máté Juhász Dec 10 '15 at 12:18
  • timestamp is an option, what is the relevant function? – stagml Dec 10 '15 at 12:47

2 Answers2

7

NEW ANSWER

If you want to have a timestamp that does not recalculate you will need to use a technique called Circular Formulas. This basically allows a cell to perform a function based on its own content.

You need to enable this functionality by going to File > Options > Formulas then ticking the Enable iterative calculation. Change the Number of iterations to 1. Press OK and save your sheet.

=IF(A1<>"",IF(B1="",NOW(),B1),"")

Explanation:

The first IF is similar to the one in the original answer. It checks if A1 is blank. <> is the logical operator meaning not equal to. The second IF checks itself and runs if content is entered into A1. If B1 is empty it enters the current date and time otherwise it outputs the existing content (the original timestamp).


ORIGINAL ANSWER

You could try this in B1:

=IF(ISBLANK(A1),"",NOW())

Explanation:

ISBLANK is a logical test that tests if the target cell has any input. It returns either TRUE or FALSE. The IF is structured so that if the target cell is blank it will output an empty string. If there is any input entered into A1 it will output the current time and date.

It should be noted that each time the sheet is recalculated the value outputted by NOW() will change to the current time.


References:

Burgi
  • 6,551
  • A well-crafted answer! – Gary's Student Dec 10 '15 at 12:16
  • THANK YOU, first comment is that I have changed "," commas to ";" in order to work out and second commet: How to avoid recalculation? – stagml Dec 10 '15 at 12:16
  • @stagml I suspect that is down to your regional settings but happy to have helped! – Burgi Dec 10 '15 at 12:18
  • How to avoid recalculation? – stagml Dec 10 '15 at 12:20
  • this is it? Menu > Excel Options > Formula > Calculation Options> Manual > Tick off "Recalculate Workbook before Saving" – stagml Dec 10 '15 at 12:51
  • Edited answer to explain circular references – Burgi Dec 10 '15 at 13:20
  • 1
    @stagml I can't say that enabling circular references for this sheet won't cause issues down the road as it appears it's an application property. It'd probably be easier to copy - paste special - values. I gave this answer +1 earlier, so don't see this as me saying it's a bad answer. – Raystafarian Dec 10 '15 at 17:11
  • Came here to answer this question with this answer! Circular references will be fine so long as that's all this particular spreadsheet does. I used this for an automatically timestamping call log. If you needed to do any analysis I'd recommend copying and pasting the raw data into another spreadsheet with circular references deactivated. – Miller86 Dec 11 '15 at 14:45
1

It's not always wise to use VBA for everything, but this is a good candidate, especially if you want to track whenever a row was changed, and not just when it was first entered. Insert the following into the code for the sheet with the timestamp column:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim intersection As Range
    ' Change A:A,C:E to whatever range you want to watch.
    Set intersection = Application.Intersect(Target, Me.Range("A:A,C:E"))
    If Not intersection Is Nothing Then
        Dim r As Range
        For Each r In intersection.Rows
            ' Change B1 to whichever column is the timestamp.
            r.EntireRow.Range("B1").Value = Now
        Next
    End If
    Application.EnableEvents = True
End Sub

In this example, columns A, C, D, and E are watched for changes, and when changes do occur, the current date and time is inserted into column B of the same row.

  • It should be noted that placing code in the Worksheet_Change() event will effectively disable undo for that worksheet because the undo stack is wiped every time VBA code that impacts workbook values is executed. – Ross McConeghy Apr 24 '17 at 20:29