Record Cell Value Change

jk64

New Member
Joined
Jun 9, 2011
Messages
11
I need a function that records the number of times a cell in a worksheet has a value change.

For example if cell J5 has the value 6 entered and that cell value is changed to 15 this would be recorded as 1 in the cell using the function. If that Cell value is then changed to 11, the cell change would be recorded as 2.
For clarity: I want to be able to put in, say, cell L5 =Cell_Value_Cahnge(J5), and have cell L5 automatically updated as the values in cell J5 change.

I'm not sure if there is a way to do this using the IF() function, but i tried and it wasnt working. I searched around teh web for help and tried taking a stab at VBA, but to no avail. I'm really new to all this code stuff so help would be very much aprreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Thanks Peter for your quick reply.

I searched though the thread and tried a couple of things, namely the code oin post 67.

Unfortunatly I am completly new to this VBA stuff, (I only discovered how to get to VBA mode on monday,) so I really couldn't get anywhere with it. Maybe I was playing with the wrong code, or maybe I was changing the wrong things, I have no clue.

Further help of any kind would be greatly appreciated.
 
Upvote 0
Try this. First create a sheet called Log. Then press ALT + F11 to open the Visual Basic Editor, in the Project window double click ThisWorkbook and paste into the white space on the right

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long, X As Variant
If Sh.Name = "Log" Then Exit Sub
If Target.HasFormula Then Exit Sub
X = Target.Value
With Application
    .EnableEvents = False
    .ScreenUpdating = False
    If Target.Count = 1 Then .Undo
End With
With Sheets("Log")
    .Unprotect Password:="pw"
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LR + 1).Value = Now
    .Range("B" & LR + 1).Value = Sh.Name
    .Range("C" & LR + 1).NumberFormat = "@"
    .Range("C" & LR + 1).Value = Target.Address(False, False)
    .Range("D" & LR + 1).Value = Target.Value
    .Range("E" & LR + 1).Value = X
    .Range("F" & LR + 1).Value = Environ("username")
    .Protect Password:="pw"
End With
If Target.Count = 1 Then Target.Value = X
On Error Resume Next
Target.Offset(, 1).Select
On Error GoTo 0
With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With
End Sub

Press ALT + Q to close the code window. Then try changing a few cells here and there and observe the entries in the Log sheet.
 
Upvote 0
Thanks again for the help Peter.

I did exactly what you said, and it did a fantastic job of recording every change to the worksheet. Unfortunatly that is not really what i wanted.

Let me try to clarify: I need something that i can type into a cell like a function, select the specific cell i want to follow, and the out be a running count (ie: 1,2,3...) of teh number of changes the cell underwent.

For example, if i want to track the number of changes to cell A1 in cell B1, I want to be able to type in: B1=function_name(A1). Then if I press enter, the output would be the running count of the number of changes to A1. So if A1 was initially 5, the I chagned it to 43, B1 would read 1. Then if I change A1 to 23, B1 would read 2.

I hope that clarifies my question, and I hope you can help.
 
Upvote 0
OK, this is specific to changes in A1 with the changes count recorded in B1. It assumes that you are changing A1 manually. Right click the sheet tab and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Static OldVal As Variant
If Target.Address(False, False) = "A1" Then
    Application.EnableEvents = False
    If Target.Value <> OldVal Then
        Target.Offset(, 1).Value = Target.Offset(, 1).Value + 1
        OldVal = Target.Value
    End If
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
That worked beautifully, Peter. Thank you.

Curious,Since I am probably going to change the tracked cell to something that is not manually changed, how would that change the code?
 
Upvote 0
f A1 contains a formula try

Code:
Private Sub Worksheet_Calculate()
Static OldVal As Variant
With Range("A1")
    Application.EnableEvents = False
    If .Value <> OldVal Then
        .Offset(, 1).Value = Target.Offset(, 1).Value + 1
        .Value
    End If
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
And what if its something like Stock prices, where it automatically updates, like a live feed?

Sorry about all of the follow ups. I just want to be sure to have exactly what I need when i put my final spreadsheet together.

Thanks for all the help Peter.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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