Results 1 to 18 of 18

How to check if a string contains one of the patterns using And & Or in If statement

Threaded View

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    How to check if a string contains one of the patterns using And & Or in If statement

    Hi there,

    I want to check a cell. If it doesn't meet one of the patterns below, it will return error msgbox.

    1. Start with "OP" and the length is 8, or
    2. Start with "DF" and the length is 10

    I wrote a code like this:

        If Not (Left(cell.value, 2)) = "OP" And Len(cell.value) = 8) Or _
                ((Left(cell.value, 2)) = "DF" And Len(cell.value) = 10) then msgbox "Error"
                End if
    However, it doesn't work. Could you please point out why?

    Thank you so much,
    Harry
    Last edited by qzqzjcjp; 09-03-2019 at 08:37 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1