Fill an Excel Worksheet With Items Based on a Code
Question details
Automatically populate a list on another worksheet with the items associated with a selected code.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A source worksheet contains codes such as 111 and 2222, with one or more corresponding products or items.
- Observed behavior
- Entering a code on the destination worksheet should display its matching items.
Arrange the source data with one code and one item per row. Check that codes are stored consistently as numbers or text, and confirm that your Excel version supports FILTER.
Use FILTER to return all items matching a code
Use this method in an Excel version that supports dynamic array formulas to display all matching items automatically.
On a worksheet named Source, enter codes in A2:A100 and their corresponding items in B2:B100. Repeat a code on each row for every item associated with it.
On the destination worksheet, enter the code to look up in cell B2.
In cell A5, enter =IF($B$2="","",FILTER(Source!$B$2:$B$100,Source!$A$2:$A$100=$B$2,"No matching items")). Adjust the sheet name and ranges to match your data.
Press Enter and change the code in B2 to display its matching items. Keep the cells below A5 clear so the results can spill into them.

Populate a Matching Item List in WPS Spreadsheets
Use a helper column and lookup formula in WPS Spreadsheets to update an item list when you change its code. The number of results is limited to the rows where you copy the formula.
- 1. Create the source list: In WPS Spreadsheets, open your workbook and name the source worksheet Source. Put codes in A2:A100 and their items in B2:B100, one item per row.
- 2. Add a helper column: In Source!C2, enter =A2&"|"&COUNTIF($A$2:A2,A2), then drag the fill handle down to C100. This gives each occurrence of a code a distinct lookup key.
- 3. Enter the code and formula: On the destination worksheet, enter a code in B2. In A5, enter =IF($B$2="","",IFERROR(INDEX(Source!$B$2:$B$100,MATCH($B$2&"|"&ROWS($A$5:A5),Source!$C$2:$C$100,0)),"")), then press Enter.
- 4. Fill down and test: Drag the fill handle from A5 down for as many items as you expect. Change B2 to another code to refresh the list; extend the source ranges and helper column if your data goes beyond row 100.

Frequently Asked Questions
How do I return every item for a code instead of just one?
Use FILTER with the code range as the condition, such as =FILTER(Source!B2:B100,Source!A2:A100=B2,"No matching items"). XLOOKUP normally returns only the first match.
Why does my FILTER formula show a spill error?
Clear any cells blocking the results below the formula. Also place the formula in a normal worksheet range rather than inside an Excel table.
What if the code exists but no items appear?
Check that the selected code and source codes use consistent number or text formats. Also check the sheet name and make sure the formula ranges include the relevant rows.
What can I use if my spreadsheet app does not support FILTER?
Create a helper column that numbers each occurrence of a code, then use INDEX and MATCH to return each item. Copy the lookup formula down enough rows to display the expected matches.




