Function Problems

Fill Group Numbers Down Duplicate Records in Excel

Khadija KhanKhadija Khan Nov 18, 2026 869 views

Question details

Fill each row with the existing group number for its country without using VBA.

Fill Group Numbers Down Duplicate Records in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Enter the formula

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.

2
Fill the formula down

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.

3
Check the results

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.

4
Replace formulas with values if needed

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.

Use INDEX and MATCH to fill each country's group number
How the formula works: MATCH finds the first occurrence of the current country from row 2 through the current row, and INDEX returns the number from the corresponding row in column B. It does not search later rows for a missing number.
Work with spreadsheets in WPS Office

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. 1. Open the workbook: Open WPS Spreadsheet and select Open to load your Excel workbook.
  2. 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. 3. Enter the formula: In C2, enter =INDEX($B$2:B2,MATCH(A2,$A$2:A2,0)).
  4. 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. 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.
Fill group numbers for repeated countries with a formulaOpen and save Microsoft Excel XLSX filesUse a familiar spreadsheet interfaceWork with spreadsheet files using the free version of WPS Office
microsoft office alternative - wps office

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.