View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Sloth
 
Posts: n/a
Default Looking up a text string

you can't do it using the lookup functions, but you might be able to do it
with the index function.

I experiment with the following list starting in A1.
123a-b45
123a-g45
a-v123456

using the following formula you can find the row number of the item
containing "a-g".
=SUMPRODUCT(--ISNUMBER(FIND("a-g",A1:A3)),ROW(A1:A3))
and if you wanted to match this number with an item in column B you could
use this formula...
=INDEX(B:B,SUMPRODUCT(--ISNUMBER(FIND("a-g",A1:A3)),ROW(A1:A3)))

This only works if the string is unique in the array. Other wise it will
return a funny number. You could use an if function using
=IF(SUMPRODUCT(--ISNUMBER(FIND("a-g",A1:A3)),ROW(A1:A3)/ROW(A1:3))=1,INDEX(B:B,SUMPRODUCT(--ISNUMBER(FIND("a-g",A1:A3)),ROW(A1:A3))),"error message")

For instance, if you had this list
123a-b45
123a-g45
a-v123456
123va-basd54

searching for "a-b" would give 5 (1+0+0+4) with the first formula I gave,
and searching for "45" would give 6 (1+2+3+0). Both of these searches would
return "error message" using the last formula.

You have a couple options depending on how you want to distinguish the
strings. Using the example you gave, how would you clarify that "AA-BB" is
not included in "AAAA-BBBB", but is included in something else like
"ZZAA-BB-YY"? Because the exact string is in both.

"clubin" wrote:

I have an issue where I am trying to lookup certain text strings and return
values corresponding to the strings from a separate worksheet. However, the
strings do not match exactly on the worksheets. For example on the sheet
with the values to lookup it will list

"AAAA-BBBB"

but on the data worksheet it will have something like

"ZZAAAA-BBBB-YY

The text string is there, but using vlookup will not work as they do not
match exactly. In addition the lookup function doesn't seem to work as there
may be other strings in the data sheet such as

"AA-BB"

which is returned from the lookup function. Is there a way to find the
exact string within other strings as part of the array on the data sheet, or
is this not possible?

Please help.

Thank you,

Chaim