Forum Discussion

nahumjaime's avatar
nahumjaime
Copper Contributor
Mar 08, 2021
Solved

Is it possible to record data in a cell whenever another specific data cell changes?

Hello,     I'm having trouble to find a way to copy in a cell the changes of another cell... let me explain myself.   In one column I have the dates of "Estimated time of Departures" of the vesse...
  • HansVogelaar's avatar
    Mar 08, 2021

    nahumjaime 

    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.

Resources