+ Reply to Thread
Results 1 to 7 of 7

LIKE operator to compare a variable to a list of "forbidden" numbers...

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    LIKE operator to compare a variable to a list of "forbidden" numbers...

    There might be a better way to handle this, but...

    For reasons unknown, Excel every once in a while chooses to run a specific one of my functions with no understandable reason. I very likely have named it something that should be a reserved word, and I will be testing that soon, but for the time being I would like to get to understand LIKE better.

    Whenever Excel runs the function that should not run it assigns one of four numbers to the first parameter (LTerm), either:
    26
    38
    50
    62
    (Yes, I noticed the interval of 12)

    What I want to learn, which hopefully I will remember but only use briefly, is to write a line like:

    If LTerm LIKE "26, 38, 50, 62" Then Exit Function

    But apparently a comma isn't the key, and when I just tried to experiment without the spaces (but retaining the comma) Excel refused to divert to my function (Which, by the way, is named LsRate).

    So, would one of you fine folks clue me onto the syntax I should be using if this is indeed possible?

    Thank-you much!!!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,885

    Re: LIKE operator to compare a variable to a list of "forbidden" numbers...

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: LIKE operator to compare a variable to a list of "forbidden" numbers...

    Just use "=". Like is for "fuzzy" criteria, but your values don't really possess a common quality that could actually speed up the comparison.
    Please Login or Register  to view this content.
    Last edited by leelnich; 08-22-2017 at 08:32 PM.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: LIKE operator to compare a variable to a list of "forbidden" numbers...

    Use Select Case statement
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: LIKE operator to compare a variable to a list of "forbidden" numbers...

    Much appreciated; with all of you experts weighing in the bottom line is that I can't group multiple numbers in one expression with LIKE as I was trying to do!

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: LIKE operator to compare a variable to a list of "forbidden" numbers...

    whats wrong with Alan's solution?

  7. #7
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: LIKE operator to compare a variable to a list of "forbidden" numbers...

    @dmcgov - Nothing! They all work and I greatly appreciate all the information I received.
    I was thinking that there was a way to group all the numbers in some fashion after one LIKE statement, and I found out that I was barking up the wrong tree!!!

+ 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] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  2. Replies: 3
    Last Post: 01-19-2006, 02:45 PM
  3. use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 PM
  4. [SOLVED] How do you insert an "or" operator in an "IF" statement.
    By Max in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 09-06-2005, 09:05 PM
  5. How do you insert an "or" operator in an "IF" statement.
    By Jim C. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  6. How do you insert an "or" operator in an "IF" statement.
    By Jim C. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. How do you insert an "or" operator in an "IF" statement.
    By Jim C. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02: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