Consulting

Results 1 to 4 of 4

Thread: Like expression with AND or OR

  1. #1
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location

    Like expression with AND or OR

    Hi to everyone ,how can i use the Like expression with an AND or OR logical operator (If that is possible). Regards
    Last edited by ksilenio; 10-31-2019 at 04:00 PM.

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi ksilenio!
    Simple example like below:

    Sub test()
    Dim s$
    s = "abcdef"
    If s Like "*def" Or s Like "xyz*" Then MsgBox "Yes" Else MsgBox "No"   'This is right use
    If s Like "*def" And s Like "xyz*" Then MsgBox "Yes" Else MsgBox "No"  'This is right use
    If s Like ("*def" Or "xyz*") Then MsgBox "Yes"  'This is wrong use
    End Sub

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    To keep your code readable:

    Sub test()
      c00 = "abcdef"
      MsgBox Format(c00 Like "*def" Or c00 Like "xyz*", "yes/no")
    End Sub

  4. #4
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    Thank you very much for your answer
    Redards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •