Search code examples
regexgoogle-sheetsgoogle-sheets-formulaarray-formulasgs-vlookup

If cell value contains value from list (wildcard match), retrieve data from a specific column


I am using Google Sheets and have two sheets, Sheet1 and Sheet2. I want to look if a certain cell in Sheet1 contains a value from column A in Sheet2. The match should be done via wildcard *value*. If there is a match, the corresponding value in column B (Sheet 2) should be retrieved.

Sheet2 looks like this: Two columns, column A is what I want to search for and column B is what I want to return if there is a match.

| Search               | Return        |
|:---------------------|:--------------|
| dog                  | Dog           |
| hound                | Dog           |
| juice                | Beverage      |
| cola                 | Beverage      |

Sheet1 looks like this, column A contains names of different things and column B contains a google sheeet formula.

| Name                 | Type          |
|:---------------------|:--------------|
| Coca-Cola            | {formula}     |
| Nuka-Cola            | {formula}     |
| Slurp Juice          | {formula}     |
| Dog                  | {formula}     |
| Cola Juice           | {formula}     |
| Doggo                | {formula}     |
| Doge                 | {formula}     |
| American Foxhound    | {formula}     |
| Mountain Dog         | {formula}     |
| The Hound            | {formula}     |

Sheet1 should look like this in the end, see column B.

| Name                 | Type          |
|:---------------------|:--------------|
| Coca-Cola            | Beverage      |
| Nuka-Cola            | Beverage      |
| Slurp Juice          | Beverage      |
| Dog                  | Dog           |
| Cola Juice           | Beverage      |
| Doggo                | Dog           |
| Doge                 | Dog           |
| American Foxhound    | Dog           |
| Mountain Dog         | Dog           |
| The Hound            | Dog           |

This is way beyond my google sheet formula skills. Right now I have the following formula in Sheet1, which did something similar before - but dosen't work at all now: =LOOKUP(2^15;SEARCH(Sheet2!A:A;*A2*);Sheet2!B:B.

If possible, I don't want to use absolute references for this, since I don't know how long Sheet2 is.


Solution

  • try:

    =ARRAYFORMULA(IFNA(VLOOKUP(IFNA(REGEXEXTRACT(LOWER(D2:D),
     LOWER(TEXTJOIN("|", 1, SORT(A2:A, 1, 0))))), A2:B, 2, 0)))
    

    0