oryan5000
oryan5000

Reputation: 91

VBA: How to insert Symbol based on cell value using character number

Objective: I would like a Green Arrow pointing upward in cell B1 if the value in cell A1 is positive, but if the value in cell A1 is negative, I'd like a Red Arrow pointing down. The macro recorder uses the output "?" when inserting symbols so I'm not sure how change the code properly. What code should I use to replace the question marks?

Char Code (Down Arrow): 2193
Char Code (Up Arrow): 2191

If Range("A1") > 0 Then
 Range("B1").Select
 ActiveCell.FormulaR1C1 = "?"
 Range("B1").Select
 With Selection.Font
    .Color = -11489280
    .TintAndShade = 0
Else 
 ActiveCell.FormulaR1C1 = "?"
 Range("B1").Select
 With Selection.Font
    .Color = -16776961
    .TintAndShade = 0

Upvotes: 1

Views: 1284

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

How about:

Sub arrow()
    With Range("B1")
        If Range("A1") > 0 Then
            .Value = "#"
            .Font.ColorIndex = 4
        Else
            .Value = "$"
            .Font.ColorIndex = 3
        End If
        .Font.Name = "Wingdings 3"
    End With
End Sub

Upvotes: 1

Related Questions