Skip to content
Free Excel Tutorials
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Data Analysis

  • How to do a t-Test in Excel?
  • Managing Conditional Formatting Rules in Excel
  • Randomize/ Shuffle List in Excel
  • Number and Text Filters Examples in Excel
  • Get column index in Excel Table

References

  • Merge tables with VLOOKUP in Excel
  • How to use Excel COLUMN Function
  • MATCH function: Description, Usage, Syntax, Examples and Explanation
  • VLOOKUP function: Description, Usage, Syntax, Examples and Explanation
  • Count rows that contain specific values in Excel

Data Validations

  • Excel Data validation number multiple 100
  • Excel Data validation must begin with
  • Excel Data validation require unique number
  • Excel Data validation must not contain
  • Excel Data validation allow weekday only

Find longest string with criteria in Excel

by

This tutorial shows how to Find longest string with criteria in Excel using the example below;

Formula

{=INDEX(range1,MATCH(MAX(LEN(range1)*(range2=criteria)),LEN(range1)*(range2=criteria),0))}

Explanation

To find the longest string in a range with criteria, you can use an array formula based on INDEX, MATCH, LEN and MAX. In the example shown, the formula in F6 is:

{=INDEX(names,MATCH(MAX(LEN(names)*(class=F5)),LEN(names)*(class=F5),0))}

Where “names” is the named range C5:C14, and “class” is the named range B5:B14.

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

How this formula works

The core of this formula is the MATCH function, which locates the position of the longest string using supplied criteria:

MATCH(MAX(LEN(names)*(class=F5)),LEN(names)*(class=F5),0)

Note MATCH is set up to perform an exact match by supplying zero for match type. For lookup value, we have:

LEN(names)*(class=F5)

The LEN function returns an array of results (lengths), one for each name in the list where class = “A” from cell F5 :

{5;6;8;6;6;0;0;0;0;0}

This effectively filters out all of Class B, and the MAX function then returns the largest value, 8.

To construct a lookup  array, we use the same approach:

LEN(names)*(class=F5)

And get the same result:

{5;6;8;6;6;0;0;0;0;0}

After LEN and MAX run, we have a MATCH formula with these values:

MATCH(8,{5;6;8;6;6;0;0;0;0;0},0))

MATCH then returns the position of 8 in the list, 3, which feeds into INDEX like this:

=INDEX(names,3)

Finally, INDEX dutifully returns the value in the 3rd position of names, which is “Jonathan”.

Post navigation

Previous Post:

COSH function: Description, Usage, Syntax, Examples and Explanation

Next Post:

Excel Data validation require unique number

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

Logical Functions

  • How to use Excel OR Function
  • Not Equal To ‘<>‘ operator in Excel
  • How to use Excel XOR Function
  • OR function Examples in Excel
  • Nested IF function example in Excel

Date Time

  • How to calculate nth day of week in month in Excel
  • Sum race time splits in Excel
  • DATEVALUE function: Description, Usage, Syntax, Examples and Explanation
  • DATEDIF function: Description, Usage, Syntax, Examples and Explanation
  • WEEKNUM function: Description, Usage, Syntax, Examples and Explanation

Grouping

  • Group numbers with VLOOKUP in Excel
  • How to randomly assign data to groups in Excel
  • How to randomly assign people to groups in Excel
  • If cell contains one of many things in Excel
  • Categorize text with keywords in Excel

General

  • How to choose page/paper size in Excel before Printing
  • How to make excel worksheets print on one page?
  • How to fill cell ranges with random text values in Excel
  • How to fill cell ranges with random number from fixed set of options in Excel
  • List sheet names with formula in Excel
© 2025 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning