VBA Date and time stamp.

Liverlee

Board Regular
Joined
Nov 8, 2018
Messages
73
Office Version
  1. 2019
Platform
  1. Windows
Hello All.

Can anyone help me with this VBA issue?

In column D users will add info. In column e i have a date stamp and in column f a time stamp. So if anyone amends the info in column d column e will update the date and column f the time.

However if i copy and paste info in to columns a-c the vba doesn't work.

Can anyone explain where it's going wrong or suggest a workable alternative

--------------------
Private Sub Worksheet_Change(ByVal Target As Range)

'Check if target cells are empty
If Target.Column = 4 And Cells(Target.Row, 1) = "" And Cells(Target.Row, 2) = "" Then

'disable events
Application.EnableEvents = False

'insert current date into column 5
Cells(Target.Row, 5) = Date

'insert current time into column 6
Cells(Target.Row, 6) = Time

'Enable events
Application.EnableEvents = True


End If
End Sub
-----------------

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
A little adjustments :

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Check if target cells are empty
If Target.Column = 4 And Cells(Target.Row, 1) = "" Or Cells(Target.Row, 2) <> "" Then

'disable events
Application.EnableEvents = False

'insert current date into column 5
Cells(Target.Row, 5) = Date

'insert current time into column 6
Cells(Target.Row, 6) = Time

'Enable events
Application.EnableEvents = True


End If
End Sub
 
Upvote 0
Solution
the vba doesn't work
That means what? Doesn't run? Does but doesn't do what you expect? Did you put a break point at the start and then paste to ensure the event takes place?
AFAIK, paste should fire that event. Why don't you just put result of Now() in one cell instead of splitting into two parts?
 
Upvote 0
Thank you Flaiban (y)

Micron, i don't know why it didn't work, i put some dummy data in d and e and f updated as expected. However when i copied and pasted info into columns, a, b, c and then went to amend d - columns e and f didn't update and shown the new time. It remained stuck with the old time stamp.

I put the results in two parts for the purposes of conditional formatting dates but it could be done in just one cell.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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