Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to record changing values in a cell in Excel?

How to record every changing value for a frequently changing cell in Excel? For example, the original value in cell C2 is 100, when changing number 100 to 200, the original value 100 will be displayed in cell D2 automatically for recording. Go ahead to change 200 to 300, number 200 will be inserted into cell D3, change 300 to 400 will display 300 to D4 and so on. The method in this article can help you to achieve it.

Record changing values in a cell with VBA code

Enable you to do smarter, faster and better

Kutools - the best office productivity tool brings 300 advanced features to Excel. Details... Download...

Office Tab - brings tabbed interface to Excel and Word, make your work much easier. Details...Download...


Record changing values in a cell with VBA code


The below VBA code can help you record every changing value in a cell in Excel. Please do as follows.

1. In the worksheet contains the cell you want to record changing values, right click the sheet tab and then click View Code from the context menu. See screenshot:

2. Then the Microsoft Visual Basic for Applications window is opening, please copy below VBA code into the Code window.

VBA code: record changing values in a cell

Dim xVal As String
'Update by Extendoffice 2018/8/22
Private Sub Worksheet_Change(ByVal Target As Range)
    Static xCount As Integer
    Application.EnableEvents = False
    If Target.Address = Range("C2").Address Then
        Range("D2").Offset(xCount, 0).Value = xVal
        xCount = xCount + 1
    Else
        If xVal <> Range("C2").Value Then
         Range("D2").Offset(xCount, 0).Value = xVal
        xCount = xCount + 1
        End If
    End If
    Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    xVal = Range("C2").Value
End Sub

Notes:

1. In the code, C2 is the cell you want to record all its changing values. D2 is the cell you will populate the first changing value of C2.

3. Press the Alt + Q keys to close the Microsoft Visual Basic for Applications window.

From now on, every time when you change values in cell C2, the previous changing values will be recorded in D2 and the cells below D2.



Excel Productivity Tools

Kutools for Excel - The Best Office Productivity Tool

  • Brings 300 powerful advanced features to Excel, enable you to do smarter, faster and better.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Office Tab - brings tabbed interface to Office, make your work much easier.

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    krishna · 1 months ago
    I tried this code for the C2 cell which contatins DDE values which changes second by second. I use this following code but not working.

    Dim xVal As String
    Private Sub Worksheet_Change(ByVal Target As Range)
    Static xCount As Integer
    Application.EnableEvents = False
    If Target.Address = Range("C2").Address Then
    Range("D2").Offset(xCount, 0).Value = xVal
    xCount = xCount + 1
    Else
    If xVal <> Range("C2").Value Then
    Range("D2").Offset(xCount, 0).Value = xVal
    xCount = xCount + 1
    End If
    End If
    Application.EnableEvents = True
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    xVal = Range("C2").Value
    End Sub
  • To post as a guest, your comment is unpublished.
    Marky Mark · 3 months ago
    Try This

    Dim xVal As String
    Dim iVal As Integer
    Private Sub Worksheet_Change(ByVal Target As Range)
    Static xCount As Integer
    iVal = Application.WorksheetFunction.Count(Range("F:F"), 1)
    xCount = iVal
    Application.EnableEvents = False
    If Target.Address = Range("C2").Address Then
    Range("E3").Offset(xCount, 0).Value = Range("C2").Value
    Range("F3").Offset(xCount, 0).Value = Now
    xCount = xCount + 1
    Else
    If xVal <> Range("C2").Value Then
    Range("E3").Offset(xCount, 0).Value = Range("C2").Value
    Range("F3").Offset(xCount, 0).Value = Now
    xCount = xCount + 1
    End If
    End If
    Application.EnableEvents = True
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    xVal = Range("C2").Value
    End Sub
  • To post as a guest, your comment is unpublished.
    Jackie · 3 months ago
    Hi! Thanks for the code, but I have a question

    Is there a way to modify the code, such that it records the value if the cell daily, or on certain days, which I specify in a separate column?


    Thanks!
  • To post as a guest, your comment is unpublished.
    Anthony · 4 months ago
    Hello, Would it be possible to apply this for more than one cell ?
  • To post as a guest, your comment is unpublished.
    John · 5 months ago
    How do I save the number as soon as it is generated not after a new number is generated? The problem I am having is the number is not recorded right away but after a second number is created; this means neither the cell that I am recording or the cell that is the target have the number...how can I record as soon as the number is generated? Thanks for your help!