Skip to main content

Find longest text string with criteria

In this tutorial, we will talk about how to look for the longest text string in a column or row with criteria in Excel with the help of INDEX, MATCH, LEN and MAX functions.

find longest text string with criteria 1

How to find the longest test string with criteria in Excel?

To quickly find the person who comes from America with the longest name listed in the name range above, a formula that combines the INDEX, MATCH, LEN and MAX functions will help you in this way: The MAX function will retrieve the largest value in the range of string lengths provided by the LEN function. Then MATCH will locate the position of the first longest value in the range and INDEX will retrieve the value at the corresponding position.

Generic syntax

=INDEX(return_range,MATCH(MAX(LEN(return_range)*(criteria_range=criteria_value)),LEN(return_range)*(criteria_range=criteria_value),0))

√ Note: This is an array formula that requires you to enter with Ctrl + Shift + Enter.

  • return_range: The range where you want the combination formula to return the longest name from. Here refers to the name range.
  • criteria_range: The range where the criteria listed. Here refers to the country range.
  • criteria_value: The criteria you set.

To find the person who comes from America with the longest name, please copy or enter the formulas below in the cell F6, and press Ctrl + Shift + Enter to get the result:

=INDEX(B5:B11,MATCH(MAX(LEN(B5:B11)*(C5:C11="America")),LEN(B5:B11)*(C5:C11="America"),0))

Or, use a cell reference to make the formula dynamic:

=INDEX(B5:B11,MATCH(MAX(LEN(B5:B11)*(C5:C11=F5)),LEN(B5:B11)*(C5:C11=F5),0))

find longest text string with criteria 2

Explanation of the formula

=INDEX(B5:B11,MATCH(MAX(LEN(B5:B11)*(C5:C11=F5)),LEN(B5:B11)*(C5:C11=F5),0))

  • LEN(B5:B11)*(C5:C11=F5): The LEN function returns an array of the lengths of each name in B5:B11 like this: {5;5;6;3;4;8;5}; The part (C5:C11=F5) checks each value in range C5:C11 if they equal to the value in F5, and generates an array like this: {FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;TRUE}, which will turn to {0;0;1;0;1;0;1} since it will be multiplied. And this is what we will get after the multiplication: {0;0;6;0;4;0;5}.
  • MAX(LEN(B5:B11)*(C5:C11=F5)) = MAX({0;0;6;0;4;0;5}): The MAX function then returns the largest value from the array {0;0;6;0;4;0;5}, which is 6.
  • MATCH(MAX(LEN(B5:B11)*(C5:C11=F5)),LEN(B5:B11)*(C5:C11=F5),0) = MATCH(6,{0;0;6;0;4;0;5},0): The match_type 0 forces the MATCH function to find the position of the first exact number 6 in the array {0;0;6;0;4;0;5}. So, it returns 3 since the number is at the 3rd position.
  • INDEX(B5:B11,MATCH(MAX(LEN(B5:B11)*(C5:C11=F5)),LEN(B5:B11)*(C5:C11=F5),0)) = INDEX(B5:B11,3): The INDEX function returns the 3rd value in the name range B5:B11, which is Oliver.

Related functions

Excel INDEX function

The Excel INDEX function returns the displayed value based on a given position from a range or an array.

Excel MATCH function

The Excel MATCH function searches for a specific value in a range of cells, and returns the relative position of the value.

Excel LEN function

The LEN function returns the number of characters in a text string.


Related Formulas

Find longest or shortest text string in a column or row

To look for the longest or shortest text string in a column or row in Excel, you can use the INDEX, MATCH, LEN and MAX or MIN functions together.

Approximate match with INDEX and MATCH

There are times when we need to find approximate matches in Excel to evaluate employees' performance, grade students’ scores, calculate postage based on weight, etc. In this tutorial, we will talk about how to use the INDEX and MATCH functions to retrieve the results we need.

Lookup closest match value with multiple criteria

In some cases, you may need to lookup the closest or approximate match value based on more than one criteria. With the combination of INDEX, MATCH and IF functions, you can quickly get it done in Excel.


The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ...
Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup...
Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List...
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...

Description


Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations