简体   繁体   中英

Array Formula with Multiple Results and Partial Match

I need help making it so that "Engine Starting" does not have be an exact match when searching.

在此处输入图片说明

I also would like to add two rows to the top to add a header, but when I do that this happens.

在此处输入图片说明

The Matches will not show the first two results. There is supposed to be a match for Engine starting in Lesson 3 and Lesson 4.

When you inserted two rows, a couple of things happened that caused the shift.

ROW($B$1:$B$1000) became ROW($B$3:$B$1002) . This is not intended to return the actual row on the worksheet. It is intended to return the position within the range referenced by the INDEX function . In your first formula, these were the same because you used INDEX($A$1:$A$1000, ... but after inserting two rows it became INDEX($A$3:$A$1002, ... . The minimum that ROW($B$3:$B$1002) would return would be 3 , not 1 so there was no way you were ever going to get the first row in $A$3:$A$1002 .

The k parameter of the SMALL function was also intended to return a series of sequential numbers (eg 1, 2, 3, ... ). It was originally ROW(C1) which would return 1 and then 2, 3, ... as the formula was filled down. This returned the smallest then the second smallest then the third smallest, etc. After inserting two rows, this became ROW(C3) which is going to return the third smallest and go on from there.

Your array¹ formula fixed to reflect the two inserted rows,

=IFERROR(INDEX($A$3:$A$1002, SMALL(IF($E$3=$B$3:$B$1002, ROW($1:$1000)), ROW(1:1))),"")

Note that ROW($1:$1000) and INDEX($A$3:$A$1002, ... do not even reflect the same rows but they are the same number of rows . ROW(1:1) will return 1, 2, 3... as it is filled down thereby returning the smallest, second smallest, third smallest, etc.

As to your non-exact match, you could apply a wildcard search in a couple of ways. I usually use a SEARCH² function for the wildcard search paired with the ISNUMBER function to deal with non-match $N/A returns.

=IFERROR(INDEX($A$3:$A$1002, SMALL(IF(ISNUMBER(SEARCH("*"&$E$3&"*", $B$3:$B$1002)), ROW($1:$1000)), ROW(1:1))),"")

Using the newer AGGREGATE³ function can dispense of having to array ¹ enter your formula.

=IFERROR(INDEX($A$3:$A$1002, AGGREGATE(15, 6, ROW($1:$1000)/ISNUMBER(SEARCH($E$3, $B$3:$B$1002)), ROW(1:1))),"")

通配符非精确搜索


¹ Array formulas need to be finalized with Ctrl + Shift + Enter↵ . Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula.

² The SEARCH function is not case-sensitive. If a case sensitive locating function is required use the FIND function instead.

³ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM