+ Reply to Thread
Results 1 to 15 of 15

VLOOKUP down -> up

  1. #1
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    VLOOKUP down -> up

    Hi,

    I want to search for the 1st number 1 imediate above the number 4 in the same column. (please see the attached file)
    I've tried VLOOKUP but it only functions UP-DOWN and not DOWN-UP....

    Can anyone help me?
    Attached Files Attached Files

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: VLOOKUP down -> up

    Good day,

    Instead of using the Vlookup, use a combination of INDEX & MATCH functions to obtain the result. Please refer attached.



    Mark the thread as SOLVED in case your problem is resolved.
    Press the star icon if this post has been helpful.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    Re: VLOOKUP down -> up

    Hi,

    I think i didn't explain myself correctly...what i want is the position of the number 1, or its address...
    So i want to search for the 1st number "1" imediate above the number 4.

    Thanks

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: VLOOKUP down -> up

    You should provide an example that better shows what your data may look like - the sample you provided would just need a MATCH() performed on the range of numbers.

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: VLOOKUP down -> up

    If there a no equals, this one wil do.

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: VLOOKUP down -> up

    If there are no equals, this one will do.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: VLOOKUP down -> up

    Array confirmed with Shift Ctrl Enter

    =MATCH(2,IF($C$7:$C$11=1,1,IF($C$7:$C$11=4,4)))

  8. #8
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    Re: VLOOKUP down -> up

    Ok,

    Thank you very much to both.
    I've tested both versions and they don't quite do it well.
    I've attached the file with both oeldere and jason.b75 versions and with more extended data that we can test it better.
    Can you take a look at it please?

    Thanks!
    Attached Files Attached Files
    Last edited by mqdias; 06-20-2012 at 04:42 AM.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: VLOOKUP down -> up

    Try this array formula (confirmed with Ctrl+Shift+Enter)

    =IF(COUNTIF(C3:C19,4),"C"&MAX(IF(C3:C19=1,ROW(C3:C19))),"")

    or

    =IF(ISNUMBER(MATCH(4,C3:C19,0)),"C"&MAX(IF(C3:C19=1,ROW(C3:C19))),"")
    Last edited by Cutter; 06-20-2012 at 07:16 AM. Reason: Added 2nd version of formula

  10. #10
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: VLOOKUP down -> up

    Cutter, those formula both appear to take the location of the last cell with a value of 1 as long as at least one cell = 4, not the last cell with a value of 1 above the last cell with a value of 4 (see posts #1 and #3)

    Best effort from me so far is

    ="C"&MAX(IF(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-2)))=1,ROW(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-2))))))

    Array confirmed.

  11. #11
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    Re: VLOOKUP down -> up

    Quote Originally Posted by Cutter View Post
    Try this array formula (confirmed with Ctrl+Shift+Enter)

    =IF(COUNTIF(C3:C19,4),"C"&MAX(IF(C3:C19=1,ROW(C3:C19))),"")

    or

    =IF(ISNUMBER(MATCH(4,C3:C19,0)),"C"&MAX(IF(C3:C19=1,ROW(C3:C19))),"")
    Dear Cutter,

    Apparently it works i just don't understand why the if statement, becaus the following works:
    ="C"&MAX(IF(C3:C19=1,ROW(C3:C19)))
    I'm going to see now jason.b75 last reply....

    Thanks in advance

  12. #12
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    Re: VLOOKUP down -> up

    Quote Originally Posted by jason.b75 View Post
    Cutter, those formula both appear to take the location of the last cell with a value of 1 as long as at least one cell = 4, not the last cell with a value of 1 above the last cell with a value of 4 (see posts #1 and #3)

    Best effort from me so far is

    ="C"&MAX(IF(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-2)))=1,ROW(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-2))))))

    Array confirmed.
    Dear jason.b75,

    I've tried it several times and it appears to work fine, but for me is very very complex...i analised avery step but i couldn't understand the logic behing this...
    OK, if you think you can explain quickly what is the logic i'll appretiate it, but if not i am pleased already with the solution you gave!

    Thanks very much!

  13. #13
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    Re: VLOOKUP down -> up

    I found an error using it: whe you cut/paste the matrix with the values in another place, it returns an error #REF.....
    Can you try this please??

    Thanks!

  14. #14
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: VLOOKUP down -> up

    It's much the same as

    ="C"&MAX(IF(C3:C19=1,ROW(C3:C19)))

    But C3:C19 is replaced with C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-2)))

    which resizes the range to "C3:last cell with 4" so that any cell with a value of 1 after the last cell with 4 are excluded. The MAX(IF()) part returns the last row with value of 4, the -2 is a correction factor as the data starts in row 3 of the sheet.

    edit:

    The error is probably coming from pasting to different rows, linking the correction factor to the top row of data should fix it.

    ="C"&MAX(IF(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-ROW($C$3)+1)))=1,ROW(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-ROW($C$3)+1))))))
    Last edited by jason.b75; 06-20-2012 at 01:02 PM.

  15. #15
    Forum Contributor
    Join Date
    12-26-2006
    Posts
    189

    Re: VLOOKUP down -> up

    Quote Originally Posted by jason.b75 View Post
    It's much the same as

    ="C"&MAX(IF(C3:C19=1,ROW(C3:C19)))

    But C3:C19 is replaced with C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-2)))

    which resizes the range to "C3:last cell with 4" so that any cell with a value of 1 after the last cell with 4 are excluded. The MAX(IF()) part returns the last row with value of 4, the -2 is a correction factor as the data starts in row 3 of the sheet.

    edit:

    The error is probably coming from pasting to different rows, linking the correction factor to the top row of data should fix it.

    ="C"&MAX(IF(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-ROW($C$3)+1)))=1,ROW(C3:INDEX($C$3:$C$19,MAX(IF($C$3:$C$19=4,ROW($C$3:$C$19)-ROW($C$3)+1))))))

    Dear jason.b75,

    I'm very very pleased with your answer and your explanation.
    It works just fine!!!

    THANK YOU VERY VERY MUCH FOR YOUR ATTENTION!!!

+ 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