+ Reply to Thread
Results 1 to 3 of 3

Regular Expression to Return "True" or False" if a word is found

  1. #1
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    Regular Expression to Return "True" or False" if a word is found

    Hello,

    I've been using regular expression in several custom functions to check and correct various things with addresses. I'd like to create one more function that simply returns True or False in the adjacent cell if the cell with the address contains one of several words. One of the problems will be c/o for "care of". It could be anywhere on the line. Not sure how to escape the back slash either.

    Please Login or Register  to view this content.
    Thank you for your help.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time. --6StringJazzer
    Last edited by 6StringJazzer; 03-02-2017 at 04:57 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Regular Expression to Return "True" or False" if a word is found

    You are searching for a static string; regular expressions may not be needed for that. I would suggest the following. Note that I suggest returning a Boolean instead of a string. I don't understand the rules for determining True or False; your current code will always return False because that's always the last line you execute. The code below will return TRUE if the string contains any of the words searched for:

    Please Login or Register  to view this content.
    If you really want to use regexp because the word boundaries are important (in addresses I don't think they are but you know what you need) then try this:

    Please Login or Register  to view this content.
    I have not tested this but would be happy to if you provide your test data.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    Re: Regular Expression to Return "True" or False" if a word is found

    Thanks Jeff. If I wanted to put all values to search for on one line, would that be possible using this this syntax?. Is there a limit to how many words i can put in the Pattern?

    I want to search the cell. And if Street, Drive, Dr., Avenue exist, then return true. As an alternative to writing each one in s separate block.

    Like this: re.Pattern = "|\bStreet\b|\Drive\b|Dr/.\b|\bAvenue\b|"
    CHECKADDRESS = CHECKADDRESS Or re.test(strLookIn)

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Check next row if value is, "FALSE," if "TRUE," return specified value from this row
    By Dave_Doodle in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-19-2015, 10:18 AM
  2. How can I get a value to return "Y" OR "N" instead of true or false
    By bunnyfrostr in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-04-2014, 05:44 PM
  3. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  4. VLookup to return "true" or "false"
    By Sph01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2011, 11:10 AM
  5. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  6. Replies: 7
    Last Post: 05-13-2006, 05:02 PM
  7. [SOLVED] IF(VLOOKUP("MYDATA", MYNAME, 4) = 0, "TRUE", "FALSE")
    By Souris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2005, 01:05 AM

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