run a macro if a certain cell value changed

pubudu

New Member
Joined
Jun 28, 2011
Messages
3
hi
i have wrote following code for get the last modified date of a cell.but the problem is whenever i double click on that cell it changes the date.but i want this macro to run if i changed existing value only.
please help on this.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 5 Then Exit Sub

    Target.Offset(0, 1) = Now
    

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Welcome to the forums!

One option would be to turn off being able to double-click in a spreadsheet to enter a cell in that column. Try:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, Cancel As Boolean)
If target.column = 5 Then
    Cancel = True
End If
End Sub
 
Upvote 0
yeah that works fine.but still if i copy value from function bar it changes the last updated time stamp.
 
Upvote 0
This feels like a messy fix, but try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurrVal As Variant
Application.EnableEvents = False
If Not Intersect(Target, Range("E:E")) Is Nothing And Target.Count = 1 Then
    CurrVal = Target.Value
    Application.Undo
    If CurrVal <> Target.Value Then
        Target.Value = CurrVal
        Target.Offset(0, 1) = Now
    End If
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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