如何检查单元格是否格式化为货币? [英] How to check if cell is formatted as Currency?

查看:98
本文介绍了如何检查单元格是否格式化为货币?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,有必要检查大量单元格是否符合许多条件.

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和StringRow是提供单元格引用的变量.

StringColumn and StringRow are variables that supply the cell reference.

我们非常感谢您的帮助.谢谢!

Your help is appreciated. Thanks!

推荐答案

假设您使用$作为货币,则可以尝试以下操作:

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.

这篇关于如何检查单元格是否格式化为货币?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆