VBA TimeStamp where Date and time are entered into different cells

10nya

New Member
Joined
Jun 25, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi everyone needing some assistance writing a VBA. I am trying to timestamp when information is entered into Cell A. I want Date to enter into Cell B and Time to enter into Cell C.
I am able to get it to work with this VBA for Date but when I add the Time it seems to slow or freeze excel. Does anyone have any suggestions?
Private Sub Worksheet_Change(ByVal Target As Range)
' Auto Date
Dim Cell As Range
For Each Cell In Target
If Cell.Column = Range("A:A").Column Then
If Cell.Value <> "" Then
Cells(Cell.Row, "B").Value = Date
Else
Cells(Cell.Row, "B").Value = ""
End If
End If
Next Cell
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
MAybe this UNTESTED
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value <> "" Then
Target.Offset(0, 1).Value = Date
Target.Offset(0, 2).NumberFormat = "h:mm:ss AM/PM"
Target.Offset(0, 2).Value = Time
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top