Forum Discussion
Is it possible to record data in a cell whenever another specific data cell changes?
- Mar 08, 2021
The following will work in the desktop versions of Excel (for Windows and MacOS), not in the online version, nor in the versions for Android and iOS.
Let's say you want to apply this to cells A2:A100.
Right-click the sheet tab of the worksheet.
Select 'View Code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range Dim dtm As String If Not Intersect(Range("A2:A100"), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False For Each rng In Intersect(Range("A2:A100"), Target) If IsDate(rng.Value) Then dtm = Format(rng.Value, "dd.mm.yyyy") If Not rng.Offset(0, 1).Value Like "*" & dtm Then If rng.Offset(0, 1).Value = "" Then rng.Offset(0, 1).Value = dtm Else rng.Offset(0, 1).Value = rng.Offset(0, 1).Value & " / " & dtm End If End If End If Next rng Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
Switch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm).
Make sure that you allow macros when you open the workbook.
The following will work in the desktop versions of Excel (for Windows and MacOS), not in the online version, nor in the versions for Android and iOS.
Let's say you want to apply this to cells A2:A100.
Right-click the sheet tab of the worksheet.
Select 'View Code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim dtm As String
If Not Intersect(Range("A2:A100"), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("A2:A100"), Target)
If IsDate(rng.Value) Then
dtm = Format(rng.Value, "dd.mm.yyyy")
If Not rng.Offset(0, 1).Value Like "*" & dtm Then
If rng.Offset(0, 1).Value = "" Then
rng.Offset(0, 1).Value = dtm
Else
rng.Offset(0, 1).Value = rng.Offset(0, 1).Value & " / " & dtm
End If
End If
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
Switch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm).
Make sure that you allow macros when you open the workbook.