• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code for date and time upon input

Pasadu

Member
Is it possible that whenever I enter data into A1, I want the current date to appear in B1..
And if it is also possible, if I enter data into cell A1, I want the current time to appear in cell C1. Thank you.
 
A VBA event demonstration to paste only to the worksheet module :​
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Application.EnableEvents = False
        If IsEmpty(Target) Then [B1:C1].ClearContents Else [B1:C1] = Array(Date, Time)
        Application.EnableEvents = True
    End If
End Sub
Do you like it ? So thanks to click on bottom right Like !​
 
Hello Pasadu,

I'm going to assume that you are wanting the event to happen in any cell in Column A. Hence, try this:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Columns("A:A")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub

Application.EnableEvents = False

      If Target.Value <> "" Then
            Target.Offset(, 1) = Date
            Target.Offset(, 2) = Time
      End If

Application.EnableEvents = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
A VBA event demonstration to paste only to the worksheet module :​
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Application.EnableEvents = False
        If IsEmpty(Target) Then [B1:C1].ClearContents Else [B1:C1] = Array(Date, Time)
        Application.EnableEvents = True
    End If
End Sub
Do you like it ? So thanks to click on bottom right Like !​
Thank You, it worked
 
Hello Pasadu,

I'm going to assume that you are wanting the event to happen in any cell in Column A. Hence, try this:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Columns("A:A")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub

Application.EnableEvents = False

      If Target.Value <> "" Then
            Target.Offset(, 1) = Date
            Target.Offset(, 2) = Time
      End If

Application.EnableEvents = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
Thank you, you went a step further for me, I appreciate it. It works perfectly.
 
Back
Top