0
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("E9")) Is Nothing Then Exit Sub
    If IsNumeric(Target.Value) Then
        If Target.Value < 0 Then
            ActiveSheet.Shapes("Rectangle 2").Fill.ForeColor.RGB = vbRed
        Else
            ActiveSheet.Shapes("Rectangle 2").Fill.ForeColor.RGB = vbGreen
        End If
    End If
End Sub

In cell E9 I have the formula:

=IF(H9="";"";INDEX(Sales!E39:P39;MATCH(Main!AE3;Sales!E34:P34;0)))

This doesn't seem to work, only if I write manually for example 500 in E9. Any solutions?

MiguelH
  • 1,415
  • 1
  • 18
  • 32

1 Answers1

1

The Sheet Change Event doesn't get triggered when the cell content is changed by a formula. To achieve this you need Sheet Calculate Event rather.

Give this a try. Place the following code on Sheet Module.

Private Sub Worksheet_Calculate()
Dim cell As Range
Set cell = Range("E9")
If IsNumeric(cell) Then
    If cell.Value < 0 Then
        ActiveSheet.Shapes("Rectangle 2").Fill.ForeColor.RGB = vbRed
    Else
        ActiveSheet.Shapes("Rectangle 2").Fill.ForeColor.RGB = vbGreen
    End If
End If
End Sub
Subodh Tiwari sktneer
  • 9,906
  • 2
  • 18
  • 22