Keep Excel References Correct When Sorting Source Data
Question details
Keep dependent values associated with the correct records when source data is sorted.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet refers to records on another sheet, and the source records need to be sorted.
- Observed behavior
- Direct cell references can point to values belonging to different records after the source data is sorted.
Check that each source record has a unique ID and that the dependent sheet contains the same IDs. When sorting, select the entire source table so each record's fields move together.
Look up each record by ID with INDEX and MATCH
Use an ID-based lookup instead of a fixed cell reference to retrieve the correct value after sorting.
In this example, the Results sheet has unique IDs in B4:B9 and the values to return in D4:D9. Cell B2 on the dependent sheet contains the ID to find.
On the Results sheet, confirm that B4:B9 contains unique IDs. On the dependent sheet, enter the matching ID in B2.
Select the dependent cell where you want the value and enter =INDEX(Results!$D$4:$D$9,MATCH($B2,Results!$B$4:$B$9,0)). Adjust the sheet name and ranges to match your data.
Drag the formula cell's fill handle down to look up the IDs in the rows below. The source ranges stay fixed while the ID reference changes by row.
On the Results sheet, select the entire source table, then use Data > Sort. Check that the dependent values still match their record IDs.

Keep sorted records linked in WPS Spreadsheets
Use INDEX and MATCH in WPS Spreadsheets to retrieve values by record ID rather than by a fixed source-cell position.
- 1. Open the workbook: Open WPS Spreadsheets and select Open to load your Excel workbook.
- 2. Check the IDs: On the source sheet, verify that each record has a unique ID. Enter the corresponding IDs on the dependent sheet.
- 3. Add the lookup: Select a dependent cell and enter =INDEX(Results!$D$4:$D$9,MATCH($B2,Results!$B$4:$B$9,0)), replacing the example ranges with your own.
- 4. Sort the source table: Select the complete source table and use Data > Sort. Verify that the returned values still correspond to the IDs.
- 5. Save the workbook: Use File > Save As and choose XLSX if you want to retain an Excel-compatible file.

Frequently Asked Questions
Why can a direct cell reference show the wrong record after sorting?
A reference such as =Results!D4 points to a cell position, not a unique record ID. If sorting places a different record in that position, the dependent cell can show the wrong record's value.
Can I use XLOOKUP instead of INDEX and MATCH?
Yes, if your Excel version supports XLOOKUP. For the example ranges, enter =XLOOKUP(B2,Results!$B$4:$B$9,Results!$D$4:$D$9) in the dependent cell.
Why does my lookup return #N/A?
Check that the ID in the dependent sheet exists in the source ID column and has the same format. For example, a number stored as text may not match a numeric ID.
What happens if I sort only one column of the source data?
Sorting one column independently can separate IDs from their related values. Select the entire source table before choosing Data > Sort so each row stays together.




