Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Posts
    4

    Unanswered: vba like-operator and escape characters

    Hi,

    I want to check whether a string contains the character sequence "#N/A" (in vba). I've tried to use the "like-operator" to perform the check. Unfortunately, "#" is reserved as a wildcard character (any numeric character). How can I tell the like-operator to treat "#" as a usual character? I've tried "\#", but this doesn't work.

    Thanks,

    Michael

  2. #2
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    Use the VBA function InStr to find the character sequence you want. See Help for the full syntax. This will return a number of the first character that matches your sequence or a 0 if no match is found. For example:

    If InStr("There is an error #n/a","#n/a") Then
    MsgBox "#N/A has been found"
    Else
    Msgbox "No error has been found
    Endif

    Justin

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    I'm not entirely sure (haven't tested extensively), but the following seems to work if you'd like trying the like operator

    if strYourString like "*[#]N/A*" then
    Roy-Vidar

Posting Permissions

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