Change color of cell when formula result changes

lara223

New Member
Joined
Sep 21, 2021
Messages
3
I have a large database that I need to be able to see when formula results change. I have the below code that will pop up a message box when there is a change. However, its not convenient for 50+ message boxes to pop up every time the power query is refreshed. Can someone help me modify the code so that the cell simply changes color instead?

VBA Code:
Private Sub Worksheet_Calculate()
    Dim rng As Range, cell As Range
    Dim CellHasChanged As Boolean
   
    Set rng = Me.Range("J3:J2000")
    For Each cell In rng.Cells
        With cell
           CellHasChanged = CBool(.ID <> .Value)
           If CellHasChanged Then
            .ID = .Value
            MsgBox "Cell " & cell.Parent.Name & cell.Address & " has changed.", vbInformation, "Cell Value Changed"
            Exit For
           End If
        End With
    Next cell
    Set rng = Nothing
End Sub

Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Calculate()
    Dim rng As Range, cell As Range
    Dim CellHasChanged As Boolean
   
    Set rng = Me.Range("J3:J2000")
    For Each cell In rng.Cells
        With cell
           CellHasChanged = CBool(.ID <> .Value)
           If CellHasChanged Then
               .ID = .Value
               .Interior.Color = vbRed
           Else
               .Interior.Color = xlNone
           End If
        End With
    Next cell
    Set rng = Nothing
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Calculate()
    Dim rng As Range, cell As Range
    Dim CellHasChanged As Boolean
  
    Set rng = Me.Range("J3:J2000")
    For Each cell In rng.Cells
        With cell
           CellHasChanged = CBool(.ID <> .Value)
           If CellHasChanged Then
               .ID = .Value
               .Interior.Color = vbRed
           Else
               .Interior.Color = xlNone
           End If
        End With
    Next cell
    Set rng = Nothing
End Sub
The code is able to run through when I changed to this but the cell did not change to red as I would have expected.
 
Upvote 0
Do J3:J2000 contain formulae?
 
Upvote 0
Hi,
I went to respond to your first post about my original code but then saw it deleted

@Fluff has provided same answer I was about to provide.

The code is able to run through when I changed to this but the cell did not change to red as I would have expected.

if your values are numeric try corecing the ID string to numeric

Rich (BB code):
CellHasChanged = CBool(Val(.ID) <> .Value)

BTW - welcome to forum


Dave
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top