I have a workbook where each sheet has column E labeled "Date Modified" and column F labeled "Date Created." I want that whenever I edit a cell in columns A:D, the current date is entered into cell E of that row. If I am adding a new row, I want the current date to be entered into cell F of that row. I have the following macro saved in ThisWorkbook (and I have other Subs in there that do currently run as expected, so it's not an issue with macros being disabled or anything like that.)
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox("Macro fired!")
If Not Intersect(Target, Range("A:D")) Is Nothing Then
If Target = Selection Then
ThisRow = Target.Row
If Range("F" & ThisRow) Is Nothing Then
Range("F" & ThisRow) = Date
Else
Range("E" & Target.Row) = Date
End If
End If
End If
End Sub
I don't even get the MsgBox, which makes me think the Worksheet.Change event isn't firing for some reason. (It also still doesn't work even if I remove the If Target = Selection logic, which is just intended to ensure that it works on cells that I'm updating, not that are updated by another macro, for example. Prepending ActiveSheet to each Range makes no difference either.)
Any ideas why this macro doesn't run when I edit a cell?
ThisWorkbookyou could useWorkbook_SheetChangeto handle an update on any sheet in the workbook. What's the purpose ofIf Target = Selection Thenthough ?Application.EnableEventsoff.