워크 시트에서 수백 개의 열을 읽고 데이터 형식이 알파, 숫자 또는 영숫자인지 확인하려고합니다. 그러나 수식은 열에 빈 셀이 너무 많으면 "빈"을 반환합니다. 범위에서 빈 셀을 가장 잘 무시하는 방법에 대한 조언이 있습니까? 휴대가 먼저 뭔가를 포함하는 경우Range 데이터 형식을 결정하는 VBA 수식의 범위에서 공백 셀을 무시합니다.
아래 코드를
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
셀이 비어 있으면 비교 연산자를 요청합니까? 그렇다면'IsEmpty'를 사용하십시오 –