Recording Date/Time from 1 column to another whenever a cell changes

Olyn01

New Member
Joined
Mar 12, 2019
Messages
12
Hi everyone!

I found a code on google that automatically generate date and time when a cell changes.
It is working, but I want the date and time to be recorded next to the cell with the old date and time and so on whenever the cell changes.
Can somebody give me a hand on this?

Thanks in advance!


Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)


Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer


Set WorkRng = Intersect(Application.ActiveSheet.Range("A:A"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If


End Sub
 
@NoSparks thank you! I tried it and it's only working if I just manually put anything on I114. Btw, I am using an Allen Bradley PLC and RSLinx for the software.
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
What happens if you add another worksheet to store the value of the A1 cell, I used Sheet2 here,
and use the Worksheet_Calculate event on the A1 sheet ?
Code:
Private Sub Worksheet_Calculate()
    Dim nextCol As Long
With Sheets("Sheet1")   'change sheet name as required
    If .Range("A1").Value <> Sheets("Sheet2").Range("A1").Value Then
        nextCol = .Cells(1, Columns.Count).End(xlToLeft).Column + 1
        .Cells(1, nextCol) = Now
        .Cells(1, nextCol).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
        Sheets("Sheet2").Range("A1").Value = .Range("A1").Value
    End If
End With
End Sub
My brief experience with PLCs was more than 20 years ago... ladder logic on PLC-5 with DOS 6200 software.
 
Upvote 0
@NoSparks
I added new sheet for this code to work. thank you! I just have this "Runtime error 13 type mismatch" whenever I open the file.

Oh that's too old. hehe
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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