I have vba code that changes the color of 2 shapes depending on the results of a formula in a cell (L11) the output is a numeric value of 0, 1 or 2. The formula is the following:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("L11")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value = 0 Then
ActiveSheet.Shapes.Range(Array("arrow 1")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
ActiveSheet.Shapes.Range(Array("arrow 2")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
End With
End With
End If
If Target.Value = 1 Then
ActiveSheet.Shapes.Range(Array("arrow 1")).Select
Selection.ShapeRange.ZOrder msoBringForward
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
ActiveSheet.Shapes.Range(Array("arrow 2")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
End With
End With
End If
If Target.Value = 2 Then
ActiveSheet.Shapes.Range(Array("arrow 1")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
ActiveSheet.Shapes.Range(Array("arrow 2")).Select
Selection.ShapeRange.ZOrder msoBringForward
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
End If
End If
End If
Range("H13").Select
End Sub
Any help to solve this is very much appreciated!
=if(b251="Current Owned",1,if(h13>0,2,0))
However, when I run the code, it works only if I delete the formula and manually enter the values in the cell. Can you help me with this because I don't understand why this is happening. This is the vba code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("L11")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value = 0 Then
ActiveSheet.Shapes.Range(Array("arrow 1")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
ActiveSheet.Shapes.Range(Array("arrow 2")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
End With
End With
End If
If Target.Value = 1 Then
ActiveSheet.Shapes.Range(Array("arrow 1")).Select
Selection.ShapeRange.ZOrder msoBringForward
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
ActiveSheet.Shapes.Range(Array("arrow 2")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
End With
End With
End If
If Target.Value = 2 Then
ActiveSheet.Shapes.Range(Array("arrow 1")).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.349999994
.Transparency = 0
ActiveSheet.Shapes.Range(Array("arrow 2")).Select
Selection.ShapeRange.ZOrder msoBringForward
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
End If
End If
End If
Range("H13").Select
End Sub
Any help to solve this is very much appreciated!