Forum Discussion
Robert1290
Jan 20, 2022Brass Contributor
2 columns vba timestamp
Hello All, I would love to have code which inserts a timestamp in column G whenever column F is populated, and a timestamp in column I whenever column H is populated. Your help is greatly appreciated...
- Jan 20, 2022
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 it.
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("F:F,H:H"), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False Intersect(Range("F:F,H:H"), Target).Offset(0, 1).Value = Now Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
HansVogelaar
Nov 13, 2022MVP
Like this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
If Not Intersect(Range("B:B"), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("B:B"), Target)
If rng.Value = "" Then
rng.Offset(0, 5).ClearContents
Else
rng.Offset(0, 5).Value = Now ' or Date
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
If Not Intersect(Range("H:H"), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("H:H"), Target)
If rng.Value = "" Then
rng.Offset(0, 1).ClearContents
Else
rng.Offset(0, 1).Value = Now ' or Date
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End SubAlexjjKim
Nov 13, 2022Copper Contributor
You are the greatest!!