How to Match Multiple Values in a Column in Google Sheets

Published on

Matching multiple values in a column in Google Sheets is straightforward but involves one key consideration: case sensitivity.

We generally follow three types of matching:

  1. Case-insensitive matching
  2. Case-sensitive matching
  3. Partial matching (which can also be case-sensitive or case-insensitive)

Let’s use a sample list of auto spare parts in the range A2:A in a Google Sheets file. Suppose you have an inquiry for three parts: Battery Box, Battery Plate, and Battery Cap.

Matching Multiple Values in a Column in Google Sheets

Goal:

Find out if all three parts are available by checking the inventory (in column A) with a formula. We want to match these multiple values and count the matches. If the count of matches equals the number of required parts, it means all parts are available.

Below are examples of how to achieve this.

Match Multiple Values in a Column: Case-Insensitive Formula

We’ll list the search values (Battery Box, Battery Plate, Battery Cap) in C2:C, and the auto parts inventory is in A2:A.

We’ll use the LET function to name C2:C as the “criteria” and A2:A as the “range,” simplifying the formula.

Formula #1 (Case-Insensitive Match):

=ArrayFormula(
     LET(
          range, A2:A, criteria, C2:C,
          IF(
               COUNT(MATCH(criteria, range, 0))=COUNTA(criteria),
               "In Stock","No Stock"
          )
     )
)

If you want to include the part names directly in the formula instead of referring to C2:C, replace C2:C with this:

VSTACK("Battery Box", "Battery Plate", "Battery Cap")

Explanation of Formula #1:

The MATCH function looks for each value in the “criteria” (Battery Box, Battery Plate, Battery Cap) within the “range” (A2:A). It returns the relative position for matches and #N/A for mismatches.

The IF statement checks if the COUNT of matches equals the total number of search criteria. If they match, it returns “In Stock”; otherwise, it returns “No Stock.”

Can we use XMATCH instead of MATCH?

Yes! Just replace MATCH(criteria, range, 0) with XMATCH(criteria, range).

Match Multiple Values in a Column: Case-Sensitive Formula

To differentiate between uppercase and lowercase letters when matching multiple values, we use the following formula:

Formula #2 (Case-Sensitive Match):

=ArrayFormula(
     LET(
          range, UNIQUE(A2:A), criteria, UNIQUE(C2:C),
          IF(
               SUM(--REGEXMATCH(range, "^"&TEXTJOIN("$|^", true, criteria)&"$"))=COUNTA(criteria),
               "In Stock", "No Stock"
          )
     )
)

For example, “AQ101A” and “AQ101a” would be treated as different items in this formula, while Formula #1 would treat them as the same.

Explanation of Formula #2:

The REGEXMATCH function checks each item in the “range” (A2:A) against the criteria (C2:C) using regular expressions. It returns 1 for matches and 0 for non-matches. We then use SUM to count these matches.

By applying UNIQUE to the range and criteria, we avoid counting duplicates that might otherwise interfere with the match results.

Note:

REGEXMATCH uses RE2 regular expressions. If your search string contains special characters like *+?()|, you’ll need to escape them. For example, searching for Sulphuric Acid \(H2SO4\) will correctly find the item Sulphuric Acid (H2SO4).

Partial Match Multiple Values in a Column: Case-Sensitive and Case-Insensitive

When doing partial matches (e.g., searching for “Battery” instead of “Battery Box”), you might encounter multiple matches. In this case, you can’t simply count matches because multiple rows might match the same criteria.

For partial matching, we use the SEARCH function (case-insensitive) or FIND function (case-sensitive).

Formula #3 (Case-Insensitive Partial Match):

=ArrayFormula(
     LET(
          range, A2:A, criteria, C2:C,
          IF(
               COUNTIF(BYROW(TOCOL(criteria, 1), LAMBDA(r, COUNT(SEARCH(r, range)))), ">0")=COUNTA(criteria),
               "In Stock", "No Stock"
          )
     )
)

Formula #4 (Case-Sensitive Partial Match):

=ArrayFormula(
     LET(
          range, A2:A, criteria, C2:C,
          IF(
               COUNTIF(BYROW(TOCOL(criteria, 1), LAMBDA(r, COUNT(FIND(r, range)))), ">0")=COUNTA(criteria),
               "In Stock", "No Stock"
          )
     )
)

Explanation of Partial Match Formulas:

  • SEARCH is case-insensitive, and FIND is case-sensitive.
  • BYROW applies the SEARCH or FIND function to each criterion individually.
  • We then check if there is at least one match for each criterion.

That’s all! By using these methods, you can efficiently match multiple values in a column in Google Sheets, whether you need case-insensitive, case-sensitive, or partial matches.

Resources

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.

Generate Unique Random Numbers in Excel with Dynamic Arrays

Unique random numbers refer to random numbers without duplicates. Generating such numbers is straightforward...

Lookup Previous Values Dynamically in Excel and Google Sheets

Sometimes, you may want to look up the previous values relative to the current...

Sort Data but Keep Blank Rows in Excel and Google Sheets

Using a dynamic array formula or the FILTER command, we can sort data and...

Lookup Values Under Categories in Excel and Google Sheets

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

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, the simple way to search all match values, perhaps with values in a column (I have used Col D) is:

    =arrayformula(COUNTA(ifna(MATCH(D2:D,A2:A,0))))

    =arrayformula(if(COUNTA(ifna(MATCH(D2:D,A2:A,0)))>=3,"In Stock","No Stock"))

    Or you can search for a similar match like this:

    =ArrayFormula(SUM(–ISTEXT(LOOKUP(D2:D,A2:A11))))

    =ArrayFormula(if(SUM(–ISTEXT(LOOKUP(D2:D,A2:A11)))>=3,"In Stock","No Stock"))

    • Hi, Andrea,

      Thanks for enlightening me.

      The tutorial was written by me in 2018. It was an update pending which I have done right now.

      Please check it.

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.