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 count number of times a cell is changed in Excel?

For counting number of times a cell is changed in Excel, this article can help you.

Count number of times a cell is changed with VBA code


Count number of times a cell is changed with VBA code


Please do as follows to count number of times a cell is changed in Excel.

1. In the worksheet you need to count total changes of a specified cell, right-click the sheet tab, and then click View Code from the context menu. See screenshot:

2. In the opening Microsoft Visual Basic for Applications window, please copy and paste below VBA code into the Code window.

VBA code: Count number of times a cell is changed in Excel

Dim xCount As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range, xCell As Range
    On Error Resume Next
    If Target = Range("B9") Then
        xCount = xCount + 1
        Range("C9").Value = xCount                                     
    End If
    Application.EnableEvents = False
    Set xRg = Application.Intersect(Target.Dependents, Me.Range("B9"))
    If Not xRg Is Nothing Then
        xCount = xCount + 1
        Range("C9").Value = xCount
    End If
    Application.EnableEvents = True
End Sub

Note: In the code, B9 is the cell you need to count its changes, and C9 is the cell to populate the counting result. Please change them as you need.

From now on, when changes made in cell B9, its total number of changes will be superposed and populated in cell C9 automatically.


Recommended Productivity Tools for Excel

kte tab 201905

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • 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.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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.
    JediTrader · 1 months ago
    Team,

    When I tried using :

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range, xCell As Range
    Dim xSRg, xRRg As Range
    Dim xFNum As Long

    Set xSRg = Range("B9:B1000")
    Set xRRg = Range("C9:C1000")

    carefully changing the Range and Target cells vis a vis P2:P200 and X2:X200 respectively, I dont the change-count in X Column despite myself trying to change cells across multiple rows across P2:P200.

    Any help would be greatly appreciated.

    Regards
    JT
  • To post as a guest, your comment is unpublished.
    Shiju · 3 months ago
    Hello All,

    The solution as provided under "Count Number Of Times A Cell Is Changed With VBA Code" is good if we are only tracking changes to ONE CELL. Please suggest, what modifications are needed, if the tracking is to be done for multiple cells. In case of multiple cells, the incremental counter should appear next to the cell for which the change in value is being tracked.
    • To post as a guest, your comment is unpublished.
      Shiju · 3 months ago
      Looking forward for help and assistance to have a specific VBA code, which can be applied to multiple cells in one worksheet.
      • To post as a guest, your comment is unpublished.
        crystal · 3 months ago
        Hi Shiju,
        Please try the below VBA code. Thanks for commenting.

        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim xRg As Range, xCell As Range
        Dim xSRg, xRRg As Range
        Dim xFNum As Long

        Set xSRg = Range("B9:B1000")
        Set xRRg = Range("C9:C1000")

        Application.EnableEvents = False
        On Error Resume Next
        For xFNum = 1 To xSRg.count
        If Target = xSRg.Item(xFNum) Then
        xRRg.Item(xFNum).Value = xRRg.Item(xFNum).Value + 1
        Application.EnableEvents = True
        Exit Sub
        End If
        Next xFNum
        Application.EnableEvents = True
        End Sub
  • To post as a guest, your comment is unpublished.
    Kevin · 1 years ago
    Did you figure this out. I too am interested in this for checking multiple cells. Haven’t tried it yet.
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Hi Kevin,

      The following code can help you solving the problem. Thanks for your comment.
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range, xCell As Range
      Dim xSRg, xRRg As Range
      Dim xFNum As Long

      Set xSRg = Range("B9:B1000")
      Set xRRg = Range("C9:C1000")

      Application.EnableEvents = False
      On Error Resume Next
      For xFNum = 1 To xSRg.count
      If Target = xSRg.Item(xFNum) Then
      xRRg.Item(xFNum).Value = xRRg.Item(xFNum).Value + 1
      Application.EnableEvents = True
      Exit Sub
      End If
      Next xFNum
      Application.EnableEvents = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Jan · 1 years ago
    Thank you very much ! This works great.

    But how do you get the same function/rule to work for a range of cells, along an entire column, for example?

    I have a list of my business' contacts on different rows, with their contact details in different columns, and I want a add a column that registers and counts the number of times a given cell along each row is changed. The code you gave works great, but only for one cell at a time !

    I'm new to VBA, so I would greatly appreciate your support.

    I tried adding a range of cells into the code, so instead of "B9" and "C9", as given in the example above, I played around with variations like "B:B", "C:C", or "B9:B1000" and "C9:C1000", without any success.

    Thanks in advance,
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Hi Jan,
      Please try the below VBA code. Hope it can help. Thanks for your comment.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range, xCell As Range
      Dim xSRg, xRRg As Range
      Dim xFNum As Long

      Set xSRg = Range("B9:B1000")
      Set xRRg = Range("C9:C1000")

      Application.EnableEvents = False
      On Error Resume Next
      For xFNum = 1 To xSRg.count
      If Target = xSRg.Item(xFNum) Then
      xRRg.Item(xFNum).Value = xRRg.Item(xFNum).Value + 1
      Application.EnableEvents = True
      Exit Sub
      End If
      Next xFNum
      Application.EnableEvents = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Jonathan · 9 months ago
        Hi Crystal,

        This is brilliant, on my matrix I have used this on one of the columns but I have struggled to duplicate this across multiple columns. Do you have a solution?

        Thanks in Advance