Find the Largest Current Code in an Excel Data Series
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.

- 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.
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.
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.
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").
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").
Select D2:E2 and drag the fill handle down beside the other identifiers in columns A through C.

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. 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. 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. 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. 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.

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.




