Fill Group Numbers Down Duplicate Records in Excel
Question details
Fill each row with the existing group number for its country without using VBA.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet lists countries in column A and existing group numbers in column B; duplicate country records need the same number.
- Observed behavior
- Every row for a country should display the number assigned to that country's first occurrence.
Check that country names match exactly and that the first occurrence of each country has its correct group number in column B. If a number appears only on a later row, move it to the first occurrence before using the formula.
Use INDEX and MATCH to fill each country's group number
Use this formula when the first row for each country contains its group number; the country rows do not need to be adjacent.
In cell C2, enter =INDEX($B$2:B2,MATCH(A2,$A$2:A2,0)). This assumes your data starts in row 2, with countries in column A and group numbers in column B.
Select C2 and drag its fill handle down to the last data row, or double-click the fill handle to copy the formula down adjacent records.
Compare the numbers in column C with the first occurrence of each country in columns A and B. Correct missing or inconsistent source numbers before proceeding.
Select and copy the results in column C, then use Home > Paste > Values to keep the numbers without formulas. Paste into column B instead if you want the completed numbers there.

Fill duplicate group numbers in WPS Spreadsheet
Use the same INDEX and MATCH formula in WPS Spreadsheet to populate country group numbers without VBA, then paste the results as values if needed.
- 1. Open the workbook: Open WPS Spreadsheet and select Open to load your Excel workbook.
- 2. Check the source data: Confirm that countries are in column A and that the first occurrence of each country has its group number in column B.
- 3. Enter the formula: In C2, enter =INDEX($B$2:B2,MATCH(A2,$A$2:A2,0)).
- 4. Fill and verify: Drag the fill handle from C2 down through the remaining rows, then check that each country has the expected number.
- 5. Save the results: If you need fixed numbers, copy column C and use Paste Special > Values. Select File > Save As to save the workbook in XLSX format.

Frequently Asked Questions
Do the country rows need to be sorted together?
No. The formula searches from row 2 through the current row, so matching countries can appear anywhere in that range.
What if the group number is on a later row?
Move the correct number to column B on the country's first occurrence before filling the formula. The formula returns the first occurrence's value and does not look ahead.
Can I replace the formulas with fixed numbers?
Yes. Copy the results in column C and choose Home > Paste > Values in Excel. You can paste the values into column B if that is where you want the completed numbers.
Why do two rows for the same country return different results?
Check the country cells for spelling differences or extra spaces, and verify that the formula was filled down from C2. The country text must match for MATCH to identify the same group.




