Need Timestamp in column C whenever column B cell value changes (same row)

Vbalearner85

Board Regular
Joined
Jun 9, 2019
Messages
139
Office Version
  1. 2016
Platform
  1. Windows
Hi VBA Gurus,

I want macro to record timestamp in column C whenever value in column B changes (column B is formula based upon value in column A-corresponding row).

I have below macro which does the job, but changes timestamp even if column B value is same, but column A value changes.
I need timestamp in column C to change only when column B value changes (not column A). Seeking your expertise, as I am still new to VBA

Private Sub Worksheet_Change(ByVal Target As Range)

Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 2
xTimeColumn = 3
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Now()
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xCellColumn Then
Cells(xRg.Row, xTimeColumn) = Now()
End If
Next
End If
End If
End Sub
 

Attachments

  • Timer_Macro.PNG
    Timer_Macro.PNG
    9.9 KB · Views: 20

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If your col A values are input manually and calculation is on automatic, this should do what you want:
VBA Code:
Dim Prev As String
Dim lR As Long
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2:A" & lR)) Is Nothing Then
    If Cells(Target.Row, "B") <> Prev Then
        Application.EnableEvents = False
        Cells(Target.Row, "C").Value = Now
        Application.EnableEvents = True
    End If
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
lR = Range("B" & Rows.Count).End(xlUp).Row
If Not Intersect(Target, Range("A2:A" & lR)) Is Nothing Then
    Prev = Cells(Target.Row, "B")
End If
End Sub
 
Upvote 0
A is not manual Input,but linked to data from other sheet..which changes dynamically(system fetched data).

Above code works great for manual input as you mentioned, but I am looking for formula driven change....
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xDPRg As Range
    Dim yDPRg as Range

    Application.EnableEvents = False
    On Error Resume Next

    Set yDPRg = Application.Intersect(Target,Range("A:A"))
    Set xDPRg = Target.Dependents
    Set xDPRg = yDPrg
    Set xDPRg = Application.Union(yDPrg, Target.Dependents)
    Set xDPRg = Application.Intersect(xDPRg, Range("A:A"))
  
    Application.Intersect(Range("B:B").EntireColumn,  xDPRg.EntireRow).Value = Now()
    On Error Goto 0

    Application.EnableEvents = True
End Sub
 
Upvote 0
Finally managed to have vba solution for above after some digging in...Thanks community for the support..

So macro does the job for formulas directed data in column A and pastes timestamp for instance of every change in column B (column C step not needed for my purpose..so removed it)


Private Sub Worksheet_Calculate()
Dim Cell As Range
For Each Cell In Range("A1:A142")
If Cell.Value <> Cell.Offset(0, 8).Value Then
Cell.Offset(0, 1).Value = Now
Cell.Offset(0, 8).Value = Cell.Value
End If
Next
Columns("B:B").EntireColumn.AutoFit
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,744
Messages
6,126,621
Members
449,322
Latest member
Ricardo Souza

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