Function Problems

How to Generate Sequential Codes Like U02_01P in Excel

John WilsonJohn Wilson Nov 10, 2026 869 views

Question details

The user needs to create a long sequence of alphanumeric text codes where a specific numeric portion embedded in the middle increments automatically.

How to Generate Sequential Codes Like U02_01P in Excel
Product
Excel
Device & OS
not provided
Scenario
Creating a list of custom serial numbers, product codes, or employee IDs that follow a specific formatting pattern.
Observed behavior
Manually typing sequential alphanumeric codes is time-consuming, and standard AutoFill fails to increment numbers located in the middle of a text string.
Before you start

Identify the exact structure of your text code. Determine which parts of the string remain static (like the prefix and suffix) and which specific digits need to increment.

Solution 1Recommended

Use Text Functions to Increment Middle Numbers

Extract the static text and increment the numeric portion using a combination of LEFT, MID, RIGHT, and TEXT functions.

Standard AutoFill works well for numbers at the end of a string, but when the number is in the middle (e.g., U02_01P), you must use text manipulation formulas to isolate the number, add to it, and stitch the string back together.

1
Enter the starting code

Click on cell A1 and type your initial code, for example, U02_01P.

2
Input the extraction formula

In cell A2, enter the following formula: =LEFT(A1,FIND("_",A1))&TEXT(VALUE(MID(A1,FIND("_",A1)+1,2))+1,"00")&RIGHT(A1,1)

3
Generate the next code

Press the Enter key. Cell A2 will now display the next code in the sequence, U02_02P.

4
Fill the sequence down

Click on cell A2, hover over the small square at the bottom-right corner until your cursor becomes a cross, and drag it down to generate the rest of your sequence.

Formula Breakdown: This formula finds the underscore to keep the prefix intact, extracts the 2 digits immediately following it to add 1, formats the new number with leading zeros using the TEXT function, and finally appends the last character.
Powerful Spreadsheet Tool

Easily Manage Sequential Data with WPS Spreadsheet

WPS Office provides a comprehensive Spreadsheet application that fully supports advanced text manipulation formulas, dynamic arrays, and seamless data auto-filling, making it incredibly easy to generate custom codes.

  1. 1. Open WPS Spreadsheet: Launch WPS Office, open the Spreadsheet module, and enter your starting code in a blank cell.
  2. 2. Apply the sequence formula: Type your text manipulation or SEQUENCE formula to automatically increment the specific numeric portion of your code.
  3. 3. Auto-fill your data: Simply drag the fill handle down the column to instantly generate your complete, perfectly formatted list of alphanumeric codes.
100% compatible with Microsoft Excel (.xlsx) formulas and functionsLightweight and fast for handling large datasets and complex arraysFree built-in templates for inventory, ID management, and tracking
microsoft office alternative - wps office

Frequently Asked Questions

Why does standard AutoFill not increment the middle number of my code?

Standard AutoFill is designed to recognize and increment numbers located at the very end of a text string. For numbers embedded in the middle of text, the software treats the entire string as static text, which is why specific text manipulation formulas are required to isolate and increment the internal digits.

How do I keep leading zeros when incrementing numbers in a formula?

You can preserve leading zeros by using the TEXT function. Wrapping your numeric calculation in TEXT(value, "00") ensures that single digits are formatted with a leading zero (e.g., 01, 02). Use "000" if you need three digits (e.g., 001, 002).

Can I generate a sequence without referencing a previous cell?

Yes. By using the SEQUENCE function combined with static text strings, you can generate an independent list. For example, the formula ="U02_"&TEXT(SEQUENCE(20),"00")&"P" will automatically generate 20 sequential codes without needing a starting cell to reference.