Forum Discussion
Alan_JN
Jun 12, 2023Copper Contributor
insert date when giving "OK" command
Hello everyone, How do I mark the date that I give "OK" in a cell to appear a specific text (in another cell) along with the date that was given that "OK"? For example. "paid on 10-10-2023"
HansVogelaar
Jun 12, 2023MVP
Let's say you enter OK in column D, from D2 down, and you want the date plus text in column E.
Set the number format of column E to the custom format
"Paid on "dd-mm-yyyy
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("D2:D" & Rows.Count), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("D2:D" & Rows.Count), Target)
If rng.Value = "OK" Then
rng.Offset(0, 1).Value = Date
Else
rng.Offset(0, 1).ClearContents
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub