+ Reply to Thread
Results 1 to 7 of 7

first and last text match from list

  1. #1
    Registered User
    Join Date
    08-20-2016
    Location
    Drosopila
    MS-Off Ver
    2013
    Posts
    11

    first and last text match from list

    (I have excel 2013)

    I have a list of words in a column (also in a named range), sorted alphabetically.

    I need to find the first and last words that begins with a chosen string

    For example, if I have this list of words:

    afrn
    frghy
    frntg
    frntgh
    frntjdf
    froty
    zfrn
    if my string to match is "frn", the first and last matches are "frntg" and "frntjdf"

    I have this array function to find the first match:

    Please Login or Register  to view this content.
    but it finds "afrn" instead of "frntg" (I want the matched words to start with "frn")

    and I don't know how to find the last match.
    Last edited by forilohud; 09-20-2018 at 03:55 PM. Reason: fixed formula's list separator to English standart

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,424

    Re: first and last text match from list

    There are several ways to do this. Here's just one.

    With list of words in A2:A8 and lookup segment (frn) in B1 this in B2 and filled across C2.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Match can match multiple items and multiple match_types simultaneously. {0,1}matches the first and last occurrences of 1 in the array returned by
    1/($B$1=LEFT($A$2:$A$8,LEN($B$1))).

    The {1,2} looks up the first occurrence of 1 and the rightmost number less than or equal to 2.
    Dave

  3. #3
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: first and last text match from list

    Hi,

    You don't need an Array formula for the 1st match...

    Excel 2016 (Windows) 64 bit
    A
    B
    C
    D
    E
    1
    List Criteria 1st Match Last Match
    2
    afrn frn frntg frntjdf
    3
    frghy
    4
    frntg
    5
    frntgh
    6
    frntjdf
    7
    froty
    8
    zfrn
    Sheet: Sheet77

    Excel 2016 (Windows) 64 bit
    D
    E
    1
    1st Match Last Match
    2
    =INDEX(A2:A9,MATCH(C2&"*",A2:A9,0)) =LOOKUP(2,1/SEARCH(" "&C2," "&A2:A9),A2:A9)
    Sheet: Sheet77

  4. #4
    Registered User
    Join Date
    08-20-2016
    Location
    Drosopila
    MS-Off Ver
    2013
    Posts
    11

    Re: first and last text match from list

    Quote Originally Posted by jtakw View Post
    Excel 2016 (Windows) 64 bit
    2
    - =LOOKUP(2,1/SEARCH(" "&C2," "&A2:A9),A2:A9)
    Sheet: Sheet77
    I'm scratching my head. It works, but I don't get it. How does the LOOKUP function is finding the last element, when searching for "2", since it is searching only on error values and "1"

    Untitled.png

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,409

    Re: first and last text match from list

    LOOKUP always uses the Approximate Match version that you would get when using TRUE at the end of your VLOOKUP. It'll return the LAST value that is nearst (less than) the search value. Ultimately, as you noted, the formula returns 1,#VALUE,#VALUE,1... It looks for the last value that is nearest to 2. Clearly, it doesn't have to be 2. I can be anything >=1. Most people choose 2 ' cos it's a nice number...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,424

    Re: first and last text match from list

    Also LOOKUP is one of the few Excel functions that ignores errors ... as does the approximate MATCH in the explanation post #2.

  7. #7
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: first and last text match from list

    Glad it works for you, looks like you've already been given some explanations on how it works, thanks for the feedback.

+ 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] Parce Date from Text and Match it to a list (easy if your good)
    By lougs7 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-12-2017, 11:40 AM
  2. [SOLVED] Match text in two columns with criteria list
    By T15K in forum Excel General
    Replies: 5
    Last Post: 12-24-2014, 02:46 AM
  3. Replies: 10
    Last Post: 09-18-2014, 09:36 AM
  4. [SOLVED] Change text to match that of a list of text
    By Consty1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2013, 02:18 PM
  5. Match number in list and return text
    By treesman in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-02-2013, 09:08 AM
  6. Replies: 3
    Last Post: 06-17-2013, 01:09 PM
  7. [SOLVED] Match row that contains text text string; list associated values from pivot table
    By ACurtis802 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-29-2009, 07:50 PM

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