How To Count Number Of Times A Cell Is Changed In Excel?


Tracking changes in Excel is important when you want to monitor the history of a specific cell or range of cells, especially in a collaborative environment where multiple users have access to the same workbook. By counting the number of times, a cell has been changed, you can easily keep track of the modifications made to a cell, and identify who made the changes and when they were made. In this tutorial, we will show you how to use a simple formula to count the number of times a cell is changed in Excel, and how to customize it to suit your needs. Whether you're a beginner or an experienced Excel user, this tutorial will help you improve your skills and become more efficient at tracking changes in your Excel workbooks. So, let's get started!

Count Number Of Times A Cell Is Changed

Here we will use the VBA application to complete the task. So let us see a simple process to know how you can count the number of times a cell is changed in Excel.

Step 1

Consider any excel sheet and right-click on the sheet name and select view code to open a VBA application, then copy the below-mentioned code into the text box as shown below.

Right click > View code > Insert > Module > Copy code.

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("A2") Then
      xCount = xCount + 1
      Range("B2").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("B2").Value = xCount
   End If
      Application.EnableEvents = True
End Sub

Step 2

From now on, every time we change the value in cell A2, we can see the count in cell B2, as shown below.

Note

If we need to apply for a range of cells, we can use the below code −

Private Sub Worksheet_Change(ByVal Target As Range)
   Dim xSRg As Range
   Dim xRRg As Range
   Set xSRg = Range("B9:B1000")
   Set xCell = Intersect(xSRg, Target)
   If xCell Is Nothing Then Exit Sub
   Application.EnableEvents = False
   On Error Resume Next
   Set xCell = xCell.Range("A1")
   Set xRRg = xCell.Offset(0, 1)
   xRRg.Value = xRRg.Value + 1
   Application.EnableEvents = True
End Sub

Conclusion

In this tutorial, we used a simple example to demonstrate how you can count the number of times a cell is changed in Excel to highlight a particular set of data.

Updated on: 12-Jul-2023

174 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements