且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查范围内的数据类型

更新时间:2022-06-10 05:45:26

尝试一下.将此粘贴到模块中.然后,您可以将其用作工作表公式.

Try this. Paste this in a module. You can then use it as a Worksheet formula.

我的数据库中有这段代码,该代码是从此处获取的,我对其进行了修改以满足您的需求.

I had this code in my database which was picked up from here and I modified it to suit your needs.

Public Function CellType(c)
    Application.Volatile
    Select Case True
        Case IsEmpty(c): CellType = "Blank"
        Case Application.IsText(c): CellType = "Text"
        Case Application.IsLogical(c): CellType = "Logical"
        Case Application.IsErr(c): CellType = "Error"
        Case IsDate(c): CellType = "Date"
        Case InStr(1, c.Text, ":") <> 0: CellType = "Time"
        Case InStr(1, c.Text, "%") <> 0: CellType = "Percentage"
        Case IsNumeric(c): CellType = "Value"
    End Select
End Function

ScreenShot

您可以进一步修改它,以便在Case IsNumeric(c): CellType = "Value"内添加IF子句,以使用INSTR

You can further modify it to add an IF clause inside Case IsNumeric(c): CellType = "Value" to check for decimals, Scientific notation etc using INSTR