我验证我的单元格的值。单元格的值有5个空白或空格。我正在尝试检查该单元格是否为空白或仅包含空白并且没有文本或其他字符。但是,它不起作用,单元格值是真的是空白还是空白?:
if Trim(range("A1").Value & vbNullString) = vbNullString then
'stop here and do something
end if
答案 0 :(得分:0)
有是blankspace字符很多(大部分不可见的“裸眼”),当你犯了一个Shift + Enter可进入或者支票的细胞(如
在HTML
我建议您做的是传递给一个检查单元格或文本框所有字符的函数。
可以调用从Excel式等功能:=验证(A1),或与另一个SUB
每次约会= 0时,您只有Real Spaces和Null,而没有字母,数字,特殊字符,制表符或换行符。
Public Function Verify(FullWord)
Appointments = 0
For X = 1 To Len(FullWord)
Letter = Mid(FullWord, X, 1)
Select Case Letter
'Real NULL
Case Is = ""
Case Is = vbNullChar 'Chr(0) Character having a value of 0.
Case Is = vbNullString 'String having value 0 Not the same as a zero-length string (""); used for calling external procedures. Cannot be passed to any DLL's
'Real SPACE
Case Is = " "
'Other things
Case Is = vbCr 'Chr(13) Carriage return character
Appointments = Appointments + 1
Case Is = vbLf 'Chr(10) Linefeed character
Appointments = Appointments + 1
Case Is = vbCrLf 'Chr(13) + Chr(10) Carriage return - linefeed combination
Appointments = Appointments + 1
Case Is = vbNewLine 'Chr(13) + Chr(10) New line character
Appointments = Appointments + 1
Case Is = vbTab 'Chr(9) Tab character
Appointments = Appointments + 1
Case Is = vbBack 'Chr(8) Backspace character
Appointments = Appointments + 1
Case Is = vbFormFeed 'Chr(12) Word VBA Manual - manual page break ?
Appointments = Appointments + 1
Case Is = vbVerticalTab 'Chr(11) Word VBA Manual - manual line break (Shift + Enter)
Appointments = Appointments + 1
Case Else
Appointments = Appointments + 1
End Select
Next
Verify = Appointments
End Function