问题
I have a problem finding a way for LOOKUP to search from top to bottom column. Here's the situation. I need to create a formula for Excel to search for hardware part inside a sentences.
Example :
Sentence (A1)
Customer PC can't turn on. Check motherboard. Motherboard faulty. Replace motherboard. PSU don't have enough power. Replace PSU.
Here is lookup range column(HARDWARE)
- replace PSU
- replace motherboard
result range column(HARDWARE_PART)
- PSU
- motherboard
The formula I use is
LOOKUP(9999;SEARCH(HARDWARE;A1);HARDWARE_PART)
The result will be "motherboard". Because LOOKUP will search the column from bottom to top.
What I gonna do right now is for LOOKUP to search the column from top to bottom so that it can detect another replace part.
回答1:
Using named ranges is a good step; dynamic named ranges are even better. However, they present a problem by generating confusion trying to return the correct relative row number to an INDEX function when they do not start in the first row.
My two named ranges (e.g. HARDWARE and HARDWARE_PART) used Refers to: formulas as,
=Sheet1!$AA$2:INDEX(Sheet1!$AA:$AA, MATCH("zzz",Sheet1!$AA:$AA))
=Sheet1!$AB$2:INDEX(Sheet1!$AB:$AB, MATCH("zzz",Sheet1!$AA:$AA))
This necessitated modifying the returned row by 1 since they started in the second row.
The standard formula in B1 is,
=IFERROR(INDEX(HARDWARE_PART, AGGREGATE(15, 6, (ROW(HARDWARE)-1)/ISNUMBER(SEARCH(HARDWARE, $A1)), COLUMN(A:A))), "")
Fill right for subsequent matches in descending priority.
An IFERROR function 'wrapper' can avoid showing #NUM!
errors on non-matches by substituting the error return for a zero-legth string.
If you want to reverse the priority, swap out the 15 (SMALL function) AGGREGATE¹ option for 14 (LARGE function).
Pre-xl2010 addendum
For versions of Excel that cannot use the AGGREGATE function, this standard non-CSE formula duplicates the results. In B1 as,
=IFERROR(INDEX(HARDWARE_PART, SMALL(INDEX(ROW(HARDWARE)-1+ISERROR(SEARCH(HARDWARE, $A1))*1E+99, , ), COLUMN(A:A))), "")
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.
来源:https://stackoverflow.com/questions/37108081/ms-excel-lookup-from-top-to-bottom-column