簡體   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