1
2
Based on the following example:
I want to look up for words from the $D$2:$D$6
range in sentences from the $A$2:$A$8
range and use the value from the side column (here Tag
). So far I'm doing this:
B2 formula
------------------
=IF(NOT(ISERROR(SEARCH($D$2,A2))),$E$2,
IF(NOT(ISERROR(SEARCH($D$3,A2))),$E$3,
IF(NOT(ISERROR(SEARCH($D$4,A2))),$E$4,
IF(NOT(ISERROR(SEARCH($D$5,A2))),$E$5,
IF(NOT(ISERROR(SEARCH($D$6,A2))),$E$6,
"other"
)
)
)
)
)
Although this works, my formula is as long as the number of lookup words I have, whereas I'd like to use a range to make it cleaner and easier to maintain (i.e. now if I add a lookup word I need to add an IF
statement for that word in my formula).
Is there a way to replicate above solution with a range-based formula?
I prefer this one over @bensheperd's solution as I don't have to use an array formula. To get rid of the static range I have
=LOOKUP(2^15,SEARCH(INDIRECT("D$2:D$"&COUNTA($D:$D)+1),A2),E$2:E$6)
. What's interesting is that although I haveE$2:E$6
static, it does work (i.e. it looks up for values on cells belowE$6
:) – Max – 2013-11-20T11:53:26.803I would convert columns D and E in to a table [Select the range, Insert > Table and use "words" and "tags" in the header row], then your formula can be this:
=LOOKUP(2^15,SEARCH(Table[words],A2),Table[tags])
- If you add rows to the table those will automatically be incorporated – barry houdini – 2013-11-20T11:58:23.333