Extract Search Keys and Vlookup in a Table in Google Sheets

Sometimes we may require to extract search keys and Vlookup in Google Sheets. In this Google Sheets tutorial, you can learn how to do this. Before that, I would like to darg your attention to a different scenario in the vertical lookup (Vlookup)!

What’s that?

If a ‘search key’ is part of a text (substring) in the lookup table (first column in the ‘range’), then we can use wildcard characters with the search key.

Vlookup Syntax for Reference: VLOOKUP(search_key, range, index, [is_sorted])

Though I’ve explained the same in my post titled Partial Match in Vlookup in Google Sheets, here is one example.

After this example, I’ll come to our topic of this post, i.e. how to extract search keys and Vlookup in a table in Google Sheets.

First and Last NameAdvance
Martha Thompson5400
Diana Reed5000
Harold Scott0

Copy this table and paste it into cell A1 in your new sheet.

Assume you want to find the advance paid to “Diana Reed”. You have the search key “Diana”.

Here is the partial match Vlookup using a wildcard character. Do take note of the asterisk character usage with the search key.

=vlookup("*Diana*",A1:B4,2,0)

In this Google Sheets tutorial, what we are going to do is the reverse of this.

I mean the search key is “Diana Reed” (first and last name or full name) but the lookup table column 1 has only the first names.

Here we must require to extract the search key and then do the Vlookup.

In Google Sheets, for this, we can use the Regexextract function with the Vlookup function here.

When Should One Extract Search Keys and Vlookup in Google Sheets?

I have already touched the scenario above. Now, here is one example (range A1:B4).

First NameAdvance
Martha5400
Diana5000
Harold0

My search key for vertical lookup here is “Diana Reed”. If I use the below Vlookup formula, no doubt it would return #N/A.

=vlookup("Diana Reed",A1:B4,2,0)

The reason, the search key is not available in the first column of the lookup table.

In concise, I have the first name and last name together as the search key to Vlookup a table that contains only the first names.

By extracting the search key, i.e. first name, we can do this type of vertical lookup.

Didn’t get?

Example

See the full name as the search key in cell D2. Let’s see how to systematically extract the search key (first name) only from this and use it in Vlookup in the cell E2.

Vlookup first and last name in first name column

When I say systematically extracting a search key, I mean to say match first names (A2:A4) in first and last name (D2) and extract matching string from D2.

How to extract search keys as above and Vlookup in a table in Google Sheets?

Extract Search Key for Vlookup in Google Sheets

Use the below Regexextract + Sortn formula for extracting the search key as per the above explanation.

=SORTN(REGEXEXTRACT(D2,A2:A4))

If “Martha Thompson” is the Vlookup search key, the formula would extract “Martha” after matching the first names in column A with the name in cell D2.

Extract search keys for Vlookup in Google Sheets

Let’s use this (the formula) as the search key in Vlookup.

FORMULA 1:

=vlookup(SORTN(REGEXEXTRACT(D2,A2:A4)),A1:B4,2,0)

That’s all!

How Do We Extract Multiple Search Keys and Vlookup Them in Google Sheets?

Some times we may require to use multiple search keys in Vlookup in Google Sheets. I mean to return a Vlookup array result.

This time, in my example, I have two search keys to extract. They are the first and last names as below in D2 and D3.

Extracting multiple search keys and Vlookup

We can extract multiple search keys for Vlookup using the below Regexextract + Textjoin formula. The earlier one (Regexextract + Sortn) won’t work here.

=ArrayFormula(REGEXEXTRACT(D2:D3,TEXTJOIN("|",1,A2:A4)))

Let’s use the above formula as the search keys in Vlookup (the ArrayFormula moved).

FORMULA 2:

=ArrayFormula(vlookup(REGEXEXTRACT(D2:D3,TEXTJOIN("|",1,A2:A4)),A2:B4,2,0))

The Vlookup formula above in cell E2 would return 5000 in cell E2 and 5400 in cell E3.

Conclusion

In real life, we can use the above Vlookup to assign values to a table. For example, I have a column (Sheet1!A1:A) with campaign names as follows.

A1: Conversion – Remarketing Dynamique.
A2: Conversion – Loyalty marketing.
A3: Conversion – Loyalty marketing.
A4: Conversion – Remarketing Dynamique.

In the same sheet B1:B (Sheet1!B1:B), I want to assign campaign types from a table that looks likes below (Sheet2!A1:B).

Campaign NameCampaign Type
RemarketingType 1
Loyalty marketingType 2

Here we can use the below formula that’s in line with our FORMULA 2 above.

=ArrayFormula(IFNA(vlookup(REGEXEXTRACT(A1:A,TEXTJOIN("|",1,Sheet2!A2:A4)),Sheet2!A2:B4,2,0)))

Note: Used IFNA function additionally as both the ranges are open. An open range may cause #N/A errors. The said function makes such errors blank.

That’s all about how to extract search keys and Vlookup in Google Sheets. Thanks for the stay, enjoy!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

2 COMMENTS

  1. Hi Prashanth! I have learned so much from so many of your tutorials! Thank you for taking the time to share your knowledge!

    Replacing single words with single words is easy enough, but what if my “data” column contains sentences, and what I want to replace could be 1 or 2 words in that sentence?

    Example data in my data column (Column A):
    A1: “Billie Jean is not my lover”
    A2: “Where haaas my lover gone?”
    ..

    Example of “Find Word(s) (column F) and replacement words (Column G)
    row 1: my lover | his father
    row 2: haaas | has
    etc..

    Column B “Correct Sentence” should look like this:
    B1: “Billie Jean is not his feather”
    B2: “Where has his father gone?”

    Any guidance/help is appreciated. thanks again!

    • Hi, Saed,

      It’s so nice to hear that my tutorials are helpful to you!

      Regarding your problem, I don’t have an array formula but do have a drag and drop formula based on Vlookup.

      The solution is in line with one of my earlier Google Sheets tutorial Replace Multiple Comma Separated Values in Google Sheets.

      The sentences are in A1:A2. So my formula must be inserted in cell B1 and copy-paste to B2 or if you want copy-paste to further down.

      =ArrayFormula(textjoin(" ",true,ifna(vlookup(transpose(split(regexreplace(A1," ",","),",")),{transpose(split(textjoin("|",1,REGEXREPLACE($F$1:$F$100," ","|")),"|")),transpose(split(textjoin("|",1,REGEXREPLACE($G$1:$G$100," ","|")),"|"))},2,0),transpose(split(regexreplace(A1," ",","),",")))))

      The formula searches A1 for the list of words in F1:F100 and replace matching words from G1:G100.

      See if that helps?

      Best,

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.