Register different times with macro

anvs

New Member
Joined
Apr 18, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hello!
I have the macro below for when a text is written in Col A to register the DateTime in Col B.
If there is a change to the text in Col A, I would like this macro to also record the DateTime of the last change in Col C, keeping the initial DateTime in Col B.
If there is no change in Col A, Col C will be empty.
Thanks in advance.
anvs

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim xRg As Range
Dim xCell As Range

Set xRg = Intersect(Target, Range("A:A"))
If Not xRg Is Nothing Then
On Error GoTo SafeExit
Application.EnableEvents = False
For Each xCell In xRg
Select Case True
Case VBA.IsEmpty(xCell.Offset(0, 1).Value)
xCell.Offset(0, 1).Value = Now
End Select
Next
End If
SafeExit:
Application.EnableEvents = True
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hello. You can try with:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim w
If Target.Column > 1 Then Exit Sub
Application.EnableEvents = False
  w = Target: Application.Undo
  If w <> Target Then
    Target = w
    If Target(, 2) = "" Then Target(, 2) = Now Else Target(, 3) = Now
  End If
Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
Hello. You can try with:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim w
If Target.Column > 1 Then Exit Sub
Application.EnableEvents = False
  w = Target: Application.Undo
  If w <> Target Then
    Target = w
    If Target(, 2) = "" Then Target(, 2) = Now Else Target(, 3) = Now
  End If
Application.EnableEvents = True
End Sub

Mario R

PERFECT!
Exactly what I needed!
Thank you very much.
anvs
 
Upvote 0
PERFECT!
Exactly what I needed!
Thank you very much.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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