简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM