Home » excel » excel – Change arrow color based on its label or value

excel – Change arrow color based on its label or value

Posted by: admin May 14, 2020 Leave a comment

Questions:

How do I change the color of an arrow based on its label (converted to integer); say if the value of the arrow is <50; then change the color of the arrow to green?

I encountered run-time error 438:

Object doesn’t support this property or method (Line 3).

Sub ArrowColour()
Dim nsize As Integer
nsize = CInt(ActiveSheet.Shapes.Range(Array("Left Arrow 1")).Value)
With ActiveSheet.Shapes.Range(Array("Left Arrow 1")).Fill
    If nsize < 50 Then
    .ForeColor.RGB = RGB(0, 176, 80)
    Else
    .ForeColor.RGB = RGB(255, 0, 0)
    End If
End With
End Sub
How to&Answers:

Shapes don’t have a Value property.

Try this:

Sub ArrowColour()     
    With ActiveSheet.Shapes("Left Arrow 1")
        .ForeColor.RGB = IIf(CInt(.TextFrame.Characters.Text)<50, _
                             RGB(0, 176, 80), RGB(255, 0, 0))    
    End With
End Sub

Answer:

I have found the answer:

    Sub Test()
    Dim shp As Shape
    Dim sTemp As String
    Set shp = ActiveSheet.Shapes("RightArrow")
    sTemp = shp.TextFrame.Characters.Text
    If CInt(sTemp) > 400 Then
        shp.Fill.ForeColor.RGB = RGB(255, 0, 0)
    End If
    End Sub