Reputation: 15
Can anybody explain why this works,
=LOOKUP(1E+100,SEARCH($O$2:$O$5,J6),$O$2:$O$4)
this looks up a value in a cell from a range of cells, works as intended.
But the search(O2:O5,J6) does not work on its own? so, SEARCH($O$2:$O$5,J6) returs #value err. I would think that this would return the position if found. If I pass in {""}, e.g. Search({"xyz","zyx","xsy"},J6) this works and makes sense but why doesn't a range work.
an explanation would be greatly appreciated.
Upvotes: 1
Views: 59
Reputation: 26650
The answer to your question is two-fold.
Firstly, most functions won't accept multiple values for a single argument. Getting them to do so requires that they be calculated as array formulas. You can force a function to do this manually by confirming it with CTRLSHIFTENTER (instead of just ENTER). You'll know it's entered as an array formula because curly braces {} will surround the formula in the formula bar. Once you've done that, go to the Formulas Tab -> Evaluate Formula to see the steps. With just the Search function, you'll probably get something like {#N/A!;#N/A!;11;#N/A!;#N/A!;}
. Notice that it is an array (a list) of results from the formula, with most being errors (because the text wasn't found) and one with a proper result.
This brings us to the second part of the answer, the error-handling. Again, most functions don't handle errors well. If any part of a function errors, the whole function results in that error. You can get around this with error handling functions like ISNUMBER
or IFERROR
.
So now that we know that, why does LOOKUP
work? Because it handles both cases as part of its built-in functionality. Lookup, as part of its built-in functionality because of the specifics of how it works, evaluates its arguments as arrays This means that if you feed it another function as an argument (like SEARCH
for example), it will force that function to be evaluated as an array.. A few other functions also do this, like SUMPRODUCT
and INDEX
.
Secondly, LOOKUP
already has built-in error handling. If there are errors within its arguments, it will return the answer closest to the first argument (but still underneath it). This is why the first argument in your provided LOOKUP
function is 1E+100
which means 10^100
or basically a 1 followed by 100 zeroes. Any search result found is going to be a number smaller than that, so if it finds anything, it will return that number, because everything else will result in #N/A! and LOOKUP will ignore those errors.
Upvotes: 3