Match Orders to Stock IDs Without Duplicates in Excel
Question details
Assign a matching stock ID to each order without using the same stock item more than once.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Orders and stock items have specifications that must match, and each available stock ID can be assigned to only one order.
- Observed behavior
- Each order should receive the next available stock ID for its specification; orders beyond the available quantity should return N/A.
Arrange the stock list with specifications in column A and unique stock IDs in column B, and place order specifications in column E. The example uses rows 2–100 for stock; adjust the ranges to include every stock row, and make sure specifications and stock IDs are not blank.
Use occurrence keys and XLOOKUP to assign stock IDs
Use this method in Excel versions that support XLOOKUP to match each order to a different stock row.
The helper keys combine each specification with its occurrence number. Orders are assigned stock in worksheet order, so changing the order of either list can change the assignments.
In C2, enter =A2&"|"&SUMPRODUCT(--($A$2:A2=A2)), then fill down through the last stock row.
In F2, enter =E2&"|"&SUMPRODUCT(--($E$2:E2=E2)), then fill down through the last order row.
In G2, enter =XLOOKUP(F2,$C$2:$C$100,$B$2:$B$100,"N/A"), then fill down through the last order row. Expand both stock ranges if the stock list extends beyond row 100.

Use INDEX and MATCH when XLOOKUP is unavailable
Use this alternative in older Excel versions after creating the same stock and order helper keys.
Assign Unique Stock IDs to Orders in WPS Spreadsheet
Use helper keys and INDEX/MATCH in WPS Spreadsheet to assign each matching stock item once and return N/A for orders beyond the available quantity.
- 1. Open and arrange the workbook: Open the file in WPS Spreadsheet. Put stock specifications in column A, unique stock IDs in B, and order specifications in E.
- 2. Number stock occurrences: In C2, enter =A2&"|"&SUMPRODUCT(--($A$2:A2=A2)), then fill down through the stock list.
- 3. Number order occurrences: In F2, enter =E2&"|"&SUMPRODUCT(--($E$2:E2=E2)), then fill down through the order list.
- 4. Assign the stock IDs: In G2, enter =IFERROR(INDEX($B$2:$B$100,MATCH(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(F2,"~","~~"),"*","~*"),"?","~?"),$C$2:$C$100,0)),"N/A"), then fill down. Extend the stock ranges if your list goes beyond row 100.

Frequently Asked Questions
Why does a later order return N/A?
Its occurrence number may exceed the number of stock rows with the same specification. Check that the stock lookup ranges include all available rows and that the specifications match.
Can the same stock ID appear twice in the results?
Each stock row is matched only once, but duplicate IDs in the source stock list can still produce repeated IDs. Check column B and ensure every stock item has a unique ID.
What happens if I sort the orders or stock list?
The occurrence keys follow the current row order, so sorting can change which stock IDs are assigned. Review the results after sorting either list.
What can I use if my Excel version does not have XLOOKUP?
Create the helper keys in columns C and F, then use the INDEX/MATCH formula in column G. It returns N/A when no matching occurrence is found.




