如何在string比较中忽略大小写
我有一个Excel VBA公式:
If [G56] = "Not Applicable" Then ...
这是区分大小写的。 我希望它忽略“不适用”的情况。
您可以使用LCase函数:
If LCase([G56]) = "not applicable" Then
您也可以使用专用函数比较string:
Dim result As Integer '// vbTextCompare does a case-insensitive comparison result = StrComp("Not Applicable", "NOT APPLICABLE", vbTextCompare) If result = 0 Then '// text matches End If
在这个MSDN文章中有关于StrCompare
方法的更多信息
或者在模块顶部添加Option Compare Text
:
Option Explicit Option Compare Text Sub Test() MsgBox "Not Applicable" = "Not applicable" 'True End Sub
最快的select是
StrComp(LCase$("Not Applicable"), "not applicable", vbBinaryCompare)