Forum Discussion
Automatically Update Date in Cell if Another Cell is Modified
You can achieve this in Excel by using a simple VBA (Visual Basic for Applications) macro. Here's a step-by-step guide on how to set it up:
- Open the Excel Workbook:
- Open the Excel workbook where you want to implement this functionality.
- Open the VBA Editor:
- Press Alt + F11 to open the VBA editor.
- Insert a Module:
- In the VBA editor, right-click on any item in the Project Explorer window and choose Insert -> Module. This will add a new module to your project.
- Paste the VBA Code:
- Copy and paste the following VBA code into the module window:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim modifiedCell As Range
Dim dateCell As Range
' Check if the changed cells are within the specified range
If Not Intersect(Target, Me.Range("A:A")) Is Nothing Then
' Check if only one cell is changed
If Target.Count = 1 Then
' Define the range of the date cell you want to update
Set dateCell = Intersect(Target.EntireRow, Me.Range("B:B"))
' Check if the modified cell is not empty
If Target.Value <> "" Then
' Update the date cell to the current date
dateCell.Value = Date
End If
End If
End If
End Sub
- Make sure to modify the code to match your specific worksheet and cell references. In the example code, it's set up to monitor changes in column A and update the corresponding date in column B.
- Close the VBA Editor:
- Close the VBA editor by clicking the "X" button or pressing Alt + Q.
- Save Your Workbook:
- Save your workbook as a macro-enabled workbook with the extension .xlsm to keep the VBA code.
Now, whenever a cell in column A is modified, the corresponding date in column B will be automatically updated to the current date.
Remember, Excel will ask you to enable macros when you open the workbook. You need to enable them to make the code work. Additionally, make sure to keep a backup of your workbook before implementing VBA code, especially if you are not familiar with it.
Please see the insert file with the example.
The text and steps were edited with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.