Function Problems

Find the Largest Current Code in an Excel Data Series

Natalie TaylorNatalie Taylor Nov 18, 2026 868 views

Question details

Find the largest location code and its associated largest tray code for each product or identifier in a series of structured text values.

Find the Largest Current Code in an Excel Data Series
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains product identifiers and fixed-width codes, and the user needs the highest codes for each identifier.
Observed behavior
The desired result is a three-digit maximum location code and the largest three-digit tray code associated with that location.
Before you start

Confirm that H2:H11 contains text codes in this order: a three-character product, a four-digit identifier, a three-digit identifier, a three-digit location, and a three-digit tray. Enter the first three components in A2, B2, and C2; B2 and C2 must be numeric or numeric text, and the code components must not contain wildcard characters.

Solution 1Recommended

Calculate the Largest Matching Codes in Microsoft 365

Use FILTER and MAX to find the largest location, then find the largest tray within that location, regardless of row order.

These formulas assume each code is 16 characters long and its location and tray segments contain three digits each. Adjust the ranges and character positions if your layout differs.

1
Find the largest location

Select D2 and enter =IFERROR(LET(codes,FILTER(H$2:H$11,LEFT(H$2:H$11,10)=A2&TEXT(B2,"0000")&TEXT(C2,"000")),TEXT(MAX(VALUE(MID(codes,11,3))),"000")),"No match").

2
Find the largest associated tray

Select E2 and enter =IFERROR(LET(codes,FILTER(H$2:H$11,LEFT(H$2:H$11,13)=A2&TEXT(B2,"0000")&TEXT(C2,"000")&D2),TEXT(MAX(VALUE(RIGHT(codes,3))),"000")),"No match").

3
Apply the formulas to other products

Select D2:E2 and drag the fill handle down beside the other identifiers in columns A through C.

Calculate the Largest Matching Codes in Microsoft 365
Check unmatched or invalid codes: The formulas display No match if filtering or conversion produces an error. Check the identifier values and code format if you expect a result.
Calculate codes in WPS Spreadsheets

Find Maximum Location and Tray Codes in WPS Spreadsheets

Use array formulas in WPS Spreadsheets to match fixed-width product codes and calculate the largest location and its associated tray.

  1. 1. Open and check the data: Open the workbook in WPS Spreadsheets. Confirm that A2, B2, and C2 contain the identifier components and H2:H11 contains the 16-character codes described above.
  2. 2. Calculate the location: Select D2 and enter =IF(COUNTIF($H$2:$H$11,$A2&TEXT($B2,"0000")&TEXT($C2,"000")&"*")=0,"No match",TEXT(MAX(IF(LEFT($H$2:$H$11,10)=$A2&TEXT($B2,"0000")&TEXT($C2,"000"),IFERROR(VALUE(MID($H$2:$H$11,11,3)),0),0)),"000")). Confirm it with Ctrl+Shift+Enter if your WPS version requires array-formula entry.
  3. 3. Calculate the tray: Select E2 and enter =IF(COUNTIF($H$2:$H$11,$A2&TEXT($B2,"0000")&TEXT($C2,"000")&$D2&"*")=0,"No match",TEXT(MAX(IF(LEFT($H$2:$H$11,13)=$A2&TEXT($B2,"0000")&TEXT($C2,"000")&$D2,IFERROR(VALUE(RIGHT($H$2:$H$11,3)),0),0)),"000")). Confirm it with Ctrl+Shift+Enter if required.
  4. 4. Fill down and save: Select D2:E2 and drag the fill handle down for the remaining identifiers. Use File > Save As to save the results in your preferred workbook format.
Find maximum codes without relying on row orderPreserve three-digit results with leading zerosOpen and save Microsoft Excel XLSX and XLS filesWork in a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

Does the largest code have to appear in the last row?

No. The formulas examine all matching rows in H2:H11 and use MAX to return the largest numeric code.

Why does the tray formula refer to D2?

D2 contains the largest location. The E2 formula limits its search to rows with that location, so it returns the largest tray associated with it rather than the largest tray across all locations.

How are leading zeros preserved in the results?

TEXT(...,"000") formats each result as a three-character text value, such as 007. Keep the source codes in column H as text so their leading zeros remain in place.

What should I check if the formula returns No match?

Check that A2:C2 identify a code in H2:H11 and that each source value follows the stated 16-character layout. In the Microsoft 365 formulas, an invalid numeric segment can also cause No match.