Multiple string search with InStr in VBA

前端 未结 3 1646
耶瑟儿~
耶瑟儿~ 2021-01-18 18:11

I am checking whether a Name textbox starts with Mr. Mrs. Ms. etc.

I created a function but I am not able to compare more than one string.

Here is my code.

3条回答
  •  余生分开走
    2021-01-18 18:40

    Pass strFind as group of strings seperated by a delimiter ex:-

    FindString(LCase(Me.gname.Value), LCase("Mr;Mrs;Ms;Dr"))
    

    Now split them and compare using a loop.

    Arr = Split(strFind,";")
    Flag = 0
    
    For Each str in Arr    
      If InStr(strCheck, str) > 0 Then
      Flag = 1    
      End If
    Next
    If Flag = 1 Then
      FindString = True
    Else
      FindString = False
    End If
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题