質問

I would like to fill in the category cell of this example

Date        Description    Debit    Category

15/07/2011  Farmer Smith    10      

based on an other worksheet containing mapping values like this :

Farmer  | Groceries

I think I have to use a VLOOKUP but it doens't seem to "search" for the term ( farmer ) inside the Description cell, how do I tell my VLOOKUP to search the cell if it CONTAINS the first value and the mapping table and return the second column ( groceries ) .

Thank you

役に立ちましたか?

解決

Regarding OpenOffice Calc: AFAIK you can't modify the behaviour of VLOOKUP so it uses a CONTAINS check to determine the matching row. But if the relevant word is the the first one in the Description column in every case, you could "prepare" the lookupvalue (the first argument of the VLOOKUP function) so it just uses the first word to look for. A solution may look like this:

=VLOOKUP(LEFT(B2, FIND(" ", B2)-1), $Sheet2.$A$2:$B$4, 2, 0)

(assuming `Sheet2.A2:B4 contains the lookup array). Split on multiple lines:

=VLOOKUP(
    LEFT(
        B2,
        FIND(
            " ",
            B2
        ) -1),
    $Sheet2.$A$2:$B$4,
    2,
    0
)

The first word of the Description column is determined using LEFT and FIND.

So, with the following category table:

categories

you would get the following result:

result

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top