简体   繁体   English

VBA自定义数字格式

[英]VBA Custom NumberFormat

I have a small macro that applies a custom numberformat to a block of cells: 我有一个小宏,它将自定义数字格式应用于单元格块:

Sub Inches()
    Dim r As Range
    For Each r In Selection
        r.NumberFormat = "General"" inches"""
    Next r
End Sub

So if a cells contains 1.25 it would display as: 因此,如果一个单元格包含1.25,它将显示为:

1.25 inches 1.25英寸

I need to change this macro so that rather than inches being displayed, the double-quote character will be displayed instead. 我需要更改此宏,以便而不是显示英寸 ,而是显示双引号字符。

I have not been able to escape the double-quote's functionality. 我一直无法摆脱双引号的功能。

How about: 怎么样:

r.NumberFormat = "General"" '""'"

It's using two single quotes, not a double quote, but it may be an adequate approximation for now. 它使用的是两个单引号,而不是双引号,但目前可能是一个足够的近似值。

Try appending CHR(34) to your output string eg 尝试将CHR(34)附加到输出字符串,例如

NumberOfInches = 4 NumberOfInches = 4

Debug.Print NumberOfInches & " " & CHR(34) Debug.Print NumberOfInches&“”和CHR(34)

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

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