Forum Discussion
Automatically Update Date in Cell if Another Cell is Modified
As an example:
Let's say you want to update the date in T2:T100 if any cell in the same row in columns A to M is changed.
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the code listed below into the worksheet module.
Switch back to Excel.
Save the workbook as a macro-enabled workbook (*.xlsm).
Make sure that you allow macros when you open the workbook.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
If Not Intersect(Range("A2:M100"), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("A2:M100"), Target).Rows
Range("T" & rng.Row).Value = Date ' or Now if you want date+time
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
- JenniferGuliano_HISCOJan 04, 2024Copper Contributor
I currently have two other macros on the same worksheet - how does that work? Also, I would like to have the date updated in column I if anything changes in column H. Please note that the workbook constantly fluctuates as far as how many rows it has.
This is what I show currently:
If Target.Column = 10 Then Cells(Target.Row, 8).FormulaR1C1 = "=Vlookup(RC[2],operation,2)"
If Target.Column = 10 Then Cells(Target.Row, 12).FormulaR1C1 = "=if(or(RC[-2] = 12,RC[-2]=6),10,if(or(RC[-2] = 7,RC[-2]=3,RC[-2]=8,RC[-2]=9,RC[-2]=10),9,1))"
End Sub- HansVogelaarJan 04, 2024MVP
You enter a formula in column H if column J changes. That will happen each time you change a cell in column J - isn't that overkill. If J4 is changed 37 times, you'd enter the same formula in H4 37 times...
It also means that the user probably won't enter a value in column H directly, so the code that I posted won't work.
- JenniferGuliano_HISCOJan 04, 2024Copper Contributor
I am entering the data into field H & then I want it to know that if I change it, the current date needs to go into column I.