Function Problems

Match Orders to Stock IDs Without Duplicates in Excel

John WilsonJohn Wilson Dec 2, 2026 868 views

Question details

Assign a matching stock ID to each order without using the same stock item more than once.

Match Orders to Stock IDs Without Duplicates in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Create stock keys

In C2, enter =A2&"|"&SUMPRODUCT(--($A$2:A2=A2)), then fill down through the last stock row.

2
Create order keys

In F2, enter =E2&"|"&SUMPRODUCT(--($E$2:E2=E2)), then fill down through the last order row.

3
Return stock IDs

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 occurrence keys and XLOOKUP to assign stock IDs
Check the source data: Each stock ID must be unique in the stock list. Specifications must match between the two lists; extra spaces or different wording can prevent a match.
Match stock in WPS Spreadsheet

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. 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. 2. Number stock occurrences: In C2, enter =A2&"|"&SUMPRODUCT(--($A$2:A2=A2)), then fill down through the stock list.
  3. 3. Number order occurrences: In F2, enter =E2&"|"&SUMPRODUCT(--($E$2:E2=E2)), then fill down through the order list.
  4. 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.
Match repeated specifications without reusing a stock rowReturn N/A when matching stock runs outOpen and edit Microsoft Excel XLSX filesWork with familiar spreadsheet formulas
microsoft office alternative - wps office

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.