VBA code: Count number of times a cell is changed if cell = Yes

Copper Contributor

I'm currently using a VBA code that tells me in Cell B15 the current number of times Cell C15 has changed, and that's great, but I have other cells (Cells F16 through F100) that I'd like to have start at a base of 1 and add 1 to the base value each time the specific cell changes if the other cells are activated via the keyword "Yes" in Column D (Cells D16 through D100). Not all of the cells are going to be activated at the same time and I'd like to be able to reset the number if at all possible to have it scale up more than once.

Here is the formula I started with that is keeping track of the first changed cell.

 

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range, xCell As Range
On Error Resume Next
If Target = Range("C15") Then
xCount = xCount + 1
Range("B15").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("B14").Value = xCount
End If
Application.EnableEvents = True
End Sub

0 Replies