繁体   English   中英

VBA:如何基于使用字符数的单元格值插入符号

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

目标:如果单元格A1值为正,我希望绿色箭头指向单元格B1中,但是如果单元格A1值为负,则我希望红色箭头指向下方。 宏记录器使用输出"?" 在插入符号时,因此我不确定如何正确更改代码。 我应该使用什么代码替换问号?

字符代码(向下箭头):2193
字符代码(向上箭头):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

怎么样:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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