Skip to content
xlsoffice. All Rights Reserved
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Lookup and Reference Examples

  • How to use Excel VLOOKUP Function
  • Count rows with at least n matching values
  • How to use Excel COLUMN Function
  • How to use Excel FORMULATEXT function
  • How to get first column number in range in Excel

Data Analysis Examples

  • Number and Text Filters Examples in Excel
  • Subtotal function in Excel
  • What-If Analysis: Scenarios and Goal Seek in Excel
  • Understanding Pivot Tables in Excel
  • How to calculate correlation coefficient Correlation in Excel

Data Validation Examples

  • Excel Data validation with conditional list
  • Excel Data validation exists in list
  • Data validation must not exist in list
  • Excel Data validation must contain specific text
  • Excel Data validation unique values only

Extract all partial matches in Excel

by

This tutorial shows how to Extract all partial matches in Excel using the example below;

Formula

=IF(F5>ct,"",INDEX(data,AGGREGATE(15,6,(ROW(data)-ROW($B$5)+1)/ISNUMBER(SEARCH(search,data)),F5)))

Explanation

To extract all matches based on a partial match, you can use use an array formula based on the INDEX and AGGREGATE functions, with support from ISNUMBER and SEARCH. In the example shown, the formula in G5 is:

=IF(F5>ct,"",INDEX(data,AGGREGATE(15,6,(ROW(data)-ROW($B$5)+1)/ISNUMBER(SEARCH(search,data)),F5)))

with the following named ranges: “search” = D5, “ct” = D8, “data” = B5:B55.

Note: this is an array formula, but it does not require control + shift + enter, since AGGREGATE can handle arrays natively.

How this formula works

The core of this formula is the INDEX function, with AGGREGATE used to figure out the “nth match” for each row in the extract area:

INDEX(data,nth_match_formula)

Almost all of the work is in figuring out and reporting which rows in “data” match the search string, and reporting the position of for each matching value to INDEX. This is done with the AGGREGATE function configured like this:

AGGREGATE(15,6,(ROW(data)-ROW($B$5)+1)/ISNUMBER(SEARCH(search,data)),F5)

The first argument, 15, tells AGGREGATE to behave like SMALL, and return nth smallest values. The second argument, 6, is an option to ignore errors. The third argument is an expression that generates an array of matching results (described below). The forth argument, F5, acts like “k” in SMALL to specify the “nth” value.

Worked Example:   How to check if cell contains one of many things in Excel

AGGREGATE operates on arrays, and the expression below builds an array for the third argument inside AGGREGATE :

(ROW(data)-ROW($B$5)+1)/ISNUMBER(SEARCH(search,data))

Here, the ROW function is used to generate an array of relative row numbers, and ISNUMBER and SEARCH are used together to match the search string against values in the data, which generates an array of TRUE and FALSE values.

Worked Example:   Excel Data validation require unique number

The clever bit is to divide the row numbers by the search results. In a math operation like this, TRUE behaves like 1, and FALSE behaves like zero. The result is row numbers associated with a positive match are divided by 1 and survive the operation, while row numbers associated with non-matching values are destroyed and become #DIV/0 errors. Because AGGREGATE is set to ignore errors, it ignores the #DIV/0 errors, and returns the “nth” smallest number in the remaining values, using the number in column F for “nth”.

Worked Example:   How to get relative row numbers in a range in Excel

Managing performance

Like all array formulas, this formula is “expensive” in terms of resources with a large data set. To minimize performance impacts, the entire INDEX and MATCH formula is wrapped in IF like this:

=IF(F5>ct,"",formula)

where the named range “ct” (D8) holds this formula:

=COUNTIF(data,"*"&search&"*")

This check stops the the INDEX and AGGREGATE part of the formula from running once all matching values have been extracted.

Array formula with SMALL

If your version of Excel does not have the AGGREGATE function, you can use an alternative formula based on SMALL and IF:

=IF(F5>ct,"",INDEX(data,SMALL(IF(ISNUMBER(SEARCH(search,data)),ROW(data)-ROW($B$5)+1),F5)))

Note: this is an array formula and must be entered with control + shift + enter.

Post navigation

Previous Post:

Exact match lookup with SUMPRODUCT in Excel

Next Post:

Extract data with helper column in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others
  • DOLLAR function: Description, Usage, Syntax, Examples and Explanation
  • LEN, LENB functions: Description, Usage, Syntax, Examples and Explanation
  • How to find and replace multiple values at same time in Excel
  • Count Number of Words in Excel
  • MID, MIDB functions: Description, Usage, Syntax, Examples and Explanation
  • Add business days to date in Excel
  • MINUTE function: Description, Usage, Syntax, Examples and Explanation
  • How to calculate next scheduled event in Excel
  • Display Days in month in Excel
  • TODAY function: Description, Usage, Syntax, Examples and Explanation
  • COUPNUM function: Description, Usage, Syntax, Examples and Explanation
  • FV function: Description, Usage, Syntax, Examples and Explanation
  • RECEIVED function: Description, Usage, Syntax, Examples and Explanation
  • DURATION function: Description, Usage, Syntax, Examples and Explanation
  • SLN function: Description, Usage, Syntax, Examples and Explanation
© 2022 xlsoffice . All Right Reserved. | Teal Smiles