简体   繁体   中英

Find one cell inside a string and then populate another cell based off of that

I have a basic financial spreadsheet that I am trying to make even nicer. I have a table that looks like this:

| Description | Category | Amount

| 2341234 Chick-fil-a | Eating Out | 5.89

| 11234 Redbox/Georgetown | Entertainment | 1.21

And another table that looks like this:

| Name | Category |

| Chick-fil-a | Eating out |

| Redbox | Entertainment |

I want to find the strings from the first column of the second table in the first column of the first table and automaically populate the second column of the first table. I am pretty sure I can find the position of the string by doing a {=find(2ndSheet!A:A,1stSheetA:A)} or something of the like, but I have no idea how to populate another cell based off of that.

Does it have to be a macro?

This is a bit ugly but seems to work. It handles the situation where your description may not necessarily match the lookup table (for instance, with Redbox | Redbox/Georgetown). Replace the [Lookup_Table] with the absolute range of your lookup table, and enter as an array formula ( Control+Shift+Enter ):

=INDEX([Lookup_Table],MATCH(TRUE,NOT(ISERR((FIND([Lookup_Table],A2)))),0),2)

As for what it's doing:

=INDEX(
        [Lookup_Table],
        MATCH(
            TRUE,
            NOT(ISERR((FIND([Lookup_Table],A2)))),
            0),
         2)

It's using an INDEX formula with the [Lookup_Table] as the base range. For the row to match, it looks for instances where running the FIND formula using the current cell does not cause an error. So in the case of Redbox , you'd get an array like {#VALUE!, 7} . You then set the values to TRUE/FALSE based on whether they are errors, and then flip them so that non-errors are True . You then match the TRUE condition against that array, and a hit will return the row number in your lookup table. You then use that row number and column 2 to find the corresponding value.

Again, that is not a pretty one (and there is probably a better way to handle all of your cases), but it seems to work in my extremely exhaustive test of three rows :)

在此输入图像描述

Assuming that your first table is starts in column A , substituting this formula starting in B2 should find the value for you.

=VLOOKUP(RIGHT(A2,LEN(A2)-FIND(" ",A2,1)),[Range of Helper Table],2,FALSE)

You'll need to substitute [Range of Helper Table] with the actual range. Make sure you use absolute references using $, for example: 2ndSheet!A$2:B$20 . so that you can copy and paste.

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