Forum Discussion
use if function to enter the time
- Jan 24, 2023
=IF(DATE(YEAR(A2),MONTH(A2),DAY(A2))=TODAY(),NOW(),"")
You can try this formula which is in cell C2 in the attached file. You can enter the date (today) in any cell in range A2:A25 and the current time is returned in the adjacent cell in column C. The formula can be filled down to e.g row 1000.
Private Sub Worksheet_Change(ByVal Target As Range) Dim rngBereich As Range Set rngBereich = Range("A2:A25") If Target.Cells.Count > 1 Then GoTo done If Not Application.Intersect(Target, rngBereich) Is Nothing Then If Target.Value = Date Then Target.Offset(0, 1).Value = Now Else Target.Offset(0, 1).Value = "" End If End If done: Application.EnableEvents = True Exit Sub End Sub
An alternative could be this code. In the attached file you can enter the date in a cell in range A2:A25 and the current time is shown in the adjacent cell in column B.
=IF(DATE(YEAR(A2),MONTH(A2),DAY(A2))=TODAY(),NOW(),"")
You can try this formula which is in cell C2 in the attached file. You can enter the date (today) in any cell in range A2:A25 and the current time is returned in the adjacent cell in column C. The formula can be filled down to e.g row 1000.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngBereich As Range
Set rngBereich = Range("A2:A25")
If Target.Cells.Count > 1 Then GoTo done
If Not Application.Intersect(Target, rngBereich) Is Nothing Then
If Target.Value = Date Then
Target.Offset(0, 1).Value = Now
Else
Target.Offset(0, 1).Value = ""
End If
End If
done:
Application.EnableEvents = True
Exit Sub
End Sub
An alternative could be this code. In the attached file you can enter the date in a cell in range A2:A25 and the current time is shown in the adjacent cell in column B.
- Tom_CarsonJan 24, 2023Copper ContributorThis is amazing.
Mahalo nui loa! (Thank You Very Much)