Function Problems

Fill an Excel Worksheet With Items Based on a Code

Nimra MalikNimra Malik Dec 2, 2026 868 views

Question details

Automatically populate a list on another worksheet with the items associated with a selected code.

Fill an Excel Worksheet With Items Based on a 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.
Before you start

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.

Solution 1Recommended

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.

1
Set up the source list

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.

2
Enter the selected code

On the destination worksheet, enter the code to look up in cell B2.

3
Enter the FILTER formula

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.

4
Check the results

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.

Use FILTER to return all items matching a code
Place the formula outside an Excel table: Spilled array formulas cannot spill inside an Excel table. Place the formula in a normal worksheet range, and expand the source ranges if your data extends beyond row 100.
Work with codes in WPS Spreadsheets

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. 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. 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. 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. 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.
Automatically update the displayed items when the selected code changesOpen and edit Microsoft Excel XLSX and XLS filesUse familiar spreadsheet formulas and worksheet controlsWork with a free, lightweight office suite
microsoft office alternative - wps office

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.