Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    171
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to use the 'Like' operator to match parentheses (brackets)

    Hi all,

    I can't get the 'Like' operator to match parentheses (brackets). I want to match a pair of parentheses with a digit between them. The following is not succeeding"

    Code:
    Dim Txt As String
    Dim MyCheck As Boolean
    
    Txt = "nk2xen - configurator(1)"
    MyCheck = Txt Like "(#)"
    MyCheck is return with false.

    I tried escaping the ( by using a backslash...

    Code:
      \(
    and also by using an extra ( ...

    Code:
      ((
    But neither work.

    Ideas, anybody?

    TIA

    -avraham

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,163
    Thanks
    200
    Thanked 781 Times in 715 Posts
    Avraham,

    You want it this way: MyCheck = Txt Like "*(#)"
    The * means you don't care how many characters precede the pattern.
    If the pattern was in the middle of the string you would need an asterisk on each side of the pattern.

    Microsoft Help on Like.
    Last edited by RetiredGeek; 2011-10-10 at 18:54.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  4. The Following User Says Thank You to RetiredGeek For This Useful Post:

    amakeler (2011-10-11)

  5. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    171
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Good grief... how did I forgot that ...
    Serves me right for trying to start writing a whole new mechanism at 1:00 AM...

    I see I also copied original text instead of fabricating an example... that's how tired I was.

    Yep - it works now.

    Great thanks!

    -avraham



    Quote Originally Posted by RetiredGeek View Post
    Avraham,

    You want it this way: MyCheck = Txt Like "*(#)"
    The * means you don't care how many characters precede the pattern.
    If the pattern was in the middle of the string you would need an asterisk on each side of the pattern.

    Microsoft Help on Like.

Posting Permissions

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