不区分大小写的string比较
我试图find一种方法来显示MsgBox如果这两个string是相等的,但不看大写或小写。
For teller = 1 To 51 If Cells(teller, 5).Value = Me.txtGebruikersnaam Then MsgBox ("Deze Gebruiker bestaat al!") Exit Sub Else End If Next
我试着用:
If (StrComp(Cells(teller, 5).Value = Me.txtGebruikersnaam, vbTextCompare) = 0) Then
但它没有工作。
请尝试:
If LCase$(Cells(teller, 5).Value) = LCase$(Me.txtGebruikersnaam) Then
您在使用StrComp时确实有一个细微的错误。
原帖中的代码表示:
If (StrComp(Cells(teller, 5).Value = Me.txtGebruikersnaam, vbTextCompare) = 0) Then
问题是你有一个错字,并打算写:
If StrComp(Cells(teller, 5).Value, Me.txtGebruikersnaam, vbTextCompare) = 0 Then
细微之处在于Cells(teller, 5).Value = Me.txtGebruikersnaam
将计算为False/0
除非您有完全区分大小写的匹配,然后与vbTextCompare
进行比较, vbTextCompare
是值为1的预定义常量。
用逗号而不是平等来尝试。
PS:同样删除Excel Hero指出的额外括号。