Forum Discussion

TomR726's avatar
TomR726
Copper Contributor
Jun 27, 2023

Date last modified for individual cells

Hello,

 

I am having trouble figuring out a formula (both in cell formula and VBA, neither seems to work) to get the date an individual cell was last modified.

 

I have a drop down list in one column (equipment - see below) where users can select different status levels, and would like to track the date last modified in the next column over to see when the status was last changed. If anyone has had prior experience with this and can help I would very much appreciate it!

 

1 Reply

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    TomR726 

    To track the date when an individual cell was last modified in Excel, you can use a combination of worksheet events and VBA code.

    Here is a step-by-step guide on how to achieve this:

    1. Open the Visual Basic for Applications (VBA) editor by pressing ALT + F11 in Excel.
    2. In the Project Explorer window, locate and select the worksheet where you want to track the cell modifications.
    3. Insert a new module by clicking on "Insert" > "Module."
    4. In the module, paste the following code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range
        Set rng = Range("A1:C100") ' Modify this range to match the range where you have your drop-down list and date columns
        
        If Not Intersect(Target, rng) Is Nothing Then
            Application.EnableEvents = False
            Cells(Target.Row, "C").Value = Now ' Column C is where you want to record the last modified date
            Application.EnableEvents = True
        End If
    End Sub

    5. Replace the range "A1:C100" in the code with the actual range where your drop-down list and date columns are located. Make sure to adjust it accordingly.

    6. Close the VBA editor.

    Now, whenever a cell within the specified range is modified, the Worksheet_Change event will be triggered. The code will then update the corresponding cell in column C with the current date and time (using the Now function).

     

    Note: This code assumes that your drop-down list is located in column A, and the date column where you want to track the last modified date is column C. Modify the code according to your specific range and column requirements.

    Save the workbook as a macro-enabled (.xlsm) file and test it by making changes to the cells in the designated range. The date in column C should update accordingly.

    Remember that macros need to be enabled for this solution to work properly.

    The steps were processed with the help of AI.

Resources