In VBA get rid of the case sensitivity when comparing words?

后端 未结 4 1162
清酒与你
清酒与你 2020-12-08 06:58

I am working on an VBA program which would allow the user to type an address and find the location by matching elements of the address with a database.

Unfortunatel

4条回答
  •  甜味超标
    2020-12-08 07:28

    There is a statement you can issue at the module level:

    Option Compare Text
    

    This makes all "text comparisons" case insensitive. This means the following code will show the message "this is true":

    Option Compare Text
    
    Sub testCase()
      If "UPPERcase" = "upperCASE" Then
        MsgBox "this is true: option Compare Text has been set!"
      End If
    End Sub
    

    See for example http://www.ozgrid.com/VBA/vba-case-sensitive.htm . I'm not sure it will completely solve the problem for all instances (such as the Application.Match function) but it will take care of all the if a=b statements. As for Application.Match - you may want to convert the arguments to either upper case or lower case using the LCase function.

提交回复
热议问题