Forum Discussion

Phil-365's avatar
Phil-365
Copper Contributor
Feb 25, 2020
Solved

Running an Excel macro on cell change in a range of cells, the cell contains a formulae

I am trying to run a macro when a cell in a range of cells changes, all the cells in the range contain Formulae

  • Phil-365 You could do it like so:

    Option Explicit
    
    Dim PrevData As Variant
    
    Private Sub Worksheet_Calculate()
        Dim Rw As Long
        Dim curData As Variant
        If IsEmpty(PrevData) Then
            PrevData = Range("D2:D10").Value2
        End If
        curData = Range("D2:D10").Value2
        For Rw = LBound(curData, 1) To UBound(curData, 1)
            If curData(Rw, 1) <> PrevData(Rw, 1) Then
                MsgBox "Row " & Rw + 1 & " has changed!"
            End If
        Next
        PrevData = Range("D2:D10").Value2
    End Sub
    

8 Replies

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor
    The change event of a worksheet is only triggered by editing a cell, not if the result of a cell's formula changes.
    • Phil-365's avatar
      Phil-365
      Copper Contributor

      Thanks for your reply, Is there any way of responding to an Excel Cell that has been changed JKPieterse