+ Reply to Thread
Results 1 to 11 of 11

explanation of formula please

  1. #1
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    wales
    MS-Off Ver
    Excel 2007
    Posts
    964

    explanation of formula please

    i saw this in another thread and don't understand how it works please can someone explain it.

    =LOOKUP(REPT("z", 255), A1:F1) to return a text value in the right most cell (i have attached the sheet)


    how does

    lookup(zzzzzzzzzzzzzzzzzzzz,A1:F1) return the value required

    interested.xlsx
    The Importance of INDEX - A GUIDE TO INDEX'S OTHER USES
    <--- If a post helps hit the star

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,852

    Re: explanation of formula please

    The values in A1:F1 must be sorted for this to work. If the LOOKUP function can't find the lookup_value (i.e. "zzzzzz..."), the function matches the largest value in lookup_vector (A1:F1 in this case) that is less than or equal to lookup_value.

    Hence it finds the last item within the array.

    A similar formula can be used for finding the last number in a numerical array, i.e.:

    =LOOKUP(10E10,A1:F1)

    where 10E10 and REPT("z",255) are just very large values.

    Hope this helps.

    Pete

  3. #3
    Forum Contributor bonny24tycoon's Avatar
    Join Date
    04-02-2012
    Location
    Hell
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    405

    Re: explanation of formula please

    Welcome to the forum



    If I was able to help – PLEASE DO NOT FORGET to Click the small star icon at the bottom left of my post.
    Thanks,

    Bonny Tycoon


  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    wales
    MS-Off Ver
    Excel 2007
    Posts
    964

    Re: explanation of formula please

    Quote Originally Posted by Pete_UK View Post
    the function matches the largest value in lookup_vector (A1:F1 in this case) that is less than or equal to lookup_value.

    Pete
    so this would always be the rightmost cell with any value in even if there were cells further left with beginning with letters further up the alphabet. does largest value in lookup vector mean highest cell

    i just cant quite grasp the logic behind this

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,852

    Re: explanation of formula please

    The data has to be sorted, so your comments don't apply.

    Suppose you have:

    A, D, F, M

    in those cells. Then the formula will return M, as it is the highest value less than "zzzzzz...".

    Pete

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    wales
    MS-Off Ver
    Excel 2007
    Posts
    964

    Re: explanation of formula please

    so if you had

    A, D, F, M, B

    why whould it show B not M as M is the largest value

    or is it always the last cell

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: explanation of formula please

    LOOKUP{} returns the last value less than the target if no exact match is found.
    The data need not be sorted for this scenario.
    It's unlikely you will ever match a string that contains 255 "z"s so you get the last cell with text.

    As Pete suggests numeric values are treated differently, as are mixed data ranges

    See this workbook for more examples.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  8. #8
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    wales
    MS-Off Ver
    Excel 2007
    Posts
    964

    Re: explanation of formula please

    ok thanks i think that you and pete cleared that up for me

    cheers

    :D

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,852

    Re: explanation of formula please

    Quote Originally Posted by twiggywales View Post
    so if you had

    A, D, F, M, B

    why whould it show B not M as M is the largest value

    or is it always the last cell
    I meant to say that LOOKUP expects the data to be sorted, so in your example it will return B as that is the last cell which is less than "zzzz...", so yes, it will always return the last value in the list.

    Hope this helps.

    Pete

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: explanation of formula please

    lookup works using a binary search so it splits the data in half, tests if the lookup value is greater than the last value in the first half - if so it throws away the first half and repeats the process with what's left (if not, it throws away the second half and repeats with the first half) this continues until it finds a match or runs out of data. normally for lookup (and vlookup or hlookup with fourth argument set to TRUE) to work as you want, you need to sort the data so that the splitting works, but here the formula is looking for a value greater than any value in the list so will always end up with the last value.

  11. #11
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,109

    Re: explanation of formula please

    .............................
    Last edited by Limor_OP; 04-14-2020 at 04:55 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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