vba 如何检查单元格是否格式化为货币?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14347341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check if cell is formatted as Currency?
提问by JAGAnalyst
I am working on a project where it is necessary to check that a large number of cells meet a number of criteria.
我正在从事一个项目,该项目需要检查大量单元格是否满足多项标准。
I have been able to use the code below to check whether a cell contains a value in a numeric format. However, I also need a way to check whether a cell contains a value formatted as US Currency.
我已经能够使用下面的代码来检查单元格是否包含数字格式的值。但是,我还需要一种方法来检查单元格是否包含格式为美国货币的值。
If Not Application.WorksheetFunction.IsNumber(Range(StringColumn & StringRow).Value) Then
MsgBox "Test Failed at " & StringColumn & StringRow
Exit Sub
Else: MsgBox "Valid format for cell " & StringColumn & StringRow
End If
StringColumn and StringRow are variables that supply the cell reference.
StringColumn 和 StringRow 是提供单元格引用的变量。
Your help is appreciated. Thanks!
感谢您的帮助。谢谢!
回答by Scott Holtzman
Assuming you are using $
as your currency, you can try this:
假设您使用的$
是您的货币,您可以试试这个:
Dim strFormat as String
strFormat = Range(StringColumn & StringRow).NumberFormat
If InStr(1,strFormat,"$") = 0 Then 'not a currency format
MsgBox "Test Failed at " & StringColumn & StringRow
Exit Sub
Else: MsgBox "Valid format for cell " & StringColumn & StringRow
End If
If you have another currency, replace the $
with your currency symbol.
如果您有其他货币,请将 替换为$
您的货币符号。