Add an Occurrence Number to Repeated Items in Excel
Question details
Generate a sequential occurrence number for each repeated item and combine it with a prefix and part of the original value.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet contains item values in a column, and each occurrence needs a formatted identifier.
- Observed behavior
- Each identifier should include a fixed prefix, the first two characters of the item, and the item's occurrence number.
Place the item values in column B starting at B2, and leave column A available for the identifiers. If your data starts in a different cell, adjust the formula references to match.
Use COUNTIF to Number Each Occurrence
Use this formula to count each item's appearances from the first data row through the current row.
Select cell A2 and enter ="01-"&LEFT(B2,2)&"-"&COUNTIF(B$2:B2,B2).
Select A2 and drag the fill handle down alongside the values in column B. You can also double-click the fill handle to fill the adjacent data range.
Review column A. For example, repeated values beginning with AB produce identifiers such as 01-AB-1 and 01-AB-2.

Create Occurrence Numbers in WPS Spreadsheet
Use the same LEFT and COUNTIF formula in WPS Spreadsheet to build a prefixed identifier for each occurrence of an item.
- 1. Open your worksheet: Open WPS Spreadsheet and use Open to select your Excel workbook.
- 2. Enter the formula: With item values starting in B2, select A2 and enter ="01-"&LEFT(B2,2)&"-"&COUNTIF(B$2:B2,B2).
- 3. Fill the remaining rows: Select A2 and drag its fill handle down alongside the items in column B.
- 4. Save the workbook: Choose Menu > Save As and select an Excel format such as XLSX.

Frequently Asked Questions
How do I change the prefix in the identifier?
In the formula in A2, replace "01-" with your preferred text, such as "ITEM-", and fill the updated formula down.
Can I include more than two characters from the item?
Yes. Change LEFT(B2,2) to LEFT(B2,3) for the first three characters, then fill the formula down.
Does the formula count items with the same first two characters together?
No. COUNTIF uses the full value in column B as its criterion. Two different values can have the same displayed first two characters but separate occurrence counts.
Will sorting the rows change the occurrence numbers?
It can. The formula counts occurrences from the first data row to the current row, so recalculation after sorting may assign numbers in a different order.




