我正在尝试读取工作表上的数百列,并确定数据类型是字母、数字还是字母数字。但是,当列中有太多空单元格时,公式仍然返回" empty“。对于如何最好地忽略区域中的空单元格,有什么建议吗?
下面是代码
Function DataType(aVal As Variant) As String
Select Case TypeName(aVal)
Case "String"
If IsNumeric(aVal) Then
If LCase(aVal) Like "*d*" Then
DataType = "Alphanumeric"
Else
DataType = "numerical"
End If
Else
If aVal Like "*[0-9]*" Then
DataType = "Alphanumeric"
Else
If aVal = vbNullString Then
DataType = "null"
Else
DataType = "Alpha"
End If
End If
End If
Case "Boolean"
DataType = LCase(TypeName(aVal))
Case "Double", "Single", "Integer", "Long", "Byte"
DataType = "Numerical"
Case "Range"
DataType = DataType(aVal.Cells(1, 1).Value)
Case Else
DataType = LCase(TypeName(aVal))
End Select
End Function发布于 2016-08-27 01:17:52
首先检查您的单元格是否包含某些内容。您可以使用以下代码:
Function DataType(aVal As Variant) As String
If aVal <> "" Then
'Put the rest of your function code here
End If
End Function发布于 2016-08-27 01:19:33
像这样的东西应该就行了。
Case Else
If Not IsEmpty(aVal) Then
DataType = LCase(TypeName(aVal))
End If或者,您可以检查单元格是否与调用代码中的.SpecialCells(xlCellTypeBlanks)相交。
https://stackoverflow.com/questions/39171239
复制相似问题