Function Problems

How to Insert a Comma After Every Four Characters in Excel

Steve KSteve K Nov 10, 2026 870 views

Question details

The user needs to format a continuous text string by splitting it into groups of four characters and inserting a comma and a space between each group, regardless of the overall text length.

How to Insert a Comma After Every Four Characters in Excel
Product
Excel
Device & OS
not provided
Scenario
Formatting long, continuous text strings (like serial numbers, codes, or keys) into readable four-character segments separated by commas.
Observed behavior
A continuous string like 'qwerasdfzxcv' is successfully formatted into chunked text like 'qwer, asdf, zxcv', automatically handling lengths that are not exact multiples of four.
Before you start

Ensure you are using a modern spreadsheet application (like Microsoft 365, Excel 2021, or WPS Office) as this method relies on dynamic array functions like SEQUENCE and TEXTJOIN.

Solution 1Recommended

Use a Dynamic Array Formula (TEXTJOIN, MID, SEQUENCE)

This is the most efficient and automated way to split text into uniform chunks and join them with a custom delimiter.

This formula uses the SEQUENCE function to generate an array of starting positions for the MID function. The MID function then extracts four characters from each position. Finally, the TEXTJOIN function combines these extracted chunks together, separated by a comma and a space.

Because it calculates the total length of your text dynamically using the LEN and ROUNDUP functions, it works perfectly even if the text length is not an exact multiple of four.

1
Select a destination cell

Click on a blank cell where you want the formatted, comma-separated text to appear.

2
Enter the combination formula

Type the following formula: =TEXTJOIN(", ",TRUE,MID(A1,SEQUENCE(ROUNDUP(LEN(A1)/4,0),,,4),4)). Replace 'A1' with the cell reference that contains your original text.

3
Apply and drag

Press Enter to execute the formula. If you have a column of data, click the bottom-right corner of the cell and drag the fill handle down to apply the formula to the remaining rows.

Use a Dynamic Array Formula (TEXTJOIN, MID, SEQUENCE)
Formula Breakdown: The ROUNDUP(LEN(A1)/4,0) part determines how many 4-character chunks exist. SEQUENCE generates the start numbers (1, 5, 9, etc.), and TEXTJOIN ignores any empty results at the end.

Format Text Effortlessly with WPS Spreadsheet

WPS Office Spreadsheet fully supports dynamic array formulas, including TEXTJOIN, SEQUENCE, and MID. You can handle complex text formatting effortlessly without needing to upgrade to expensive software. It's completely free, lightweight, and highly compatible with Microsoft Excel files.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the document containing the continuous text you want to format.
  2. 2. Enter the formula: Select a blank cell next to your text and paste the formula: =TEXTJOIN(", ",TRUE,MID(A1,SEQUENCE(ROUNDUP(LEN(A1)/4,0),,,4),4)).
  3. 3. Get instant results: Press Enter. WPS Spreadsheet instantly processes the dynamic array and formats your string with commas exactly where needed.
  4. 4. Save your work: Click Save. Your perfectly formatted file remains completely compatible with Microsoft Excel formats.
Full support for advanced text functions like TEXTJOIN and SEQUENCE.Seamless format compatibility with Microsoft Excel (.xlsx, .xls).Lightweight, fast performance for large datasets.Clean, intuitive interface with built-in data processing tools.
microsoft office alternative - wps office

Frequently Asked Questions

How can I insert a comma after every Nth character instead of four?

You can easily modify the formula by changing the number '4'. For example, to insert a comma after every 5 characters, update the formula to: =TEXTJOIN(", ",TRUE,MID(A1,SEQUENCE(ROUNDUP(LEN(A1)/5,0),,,5),5)).

Why does the formula return a #NAME? error?

A #NAME? error typically means your version of Excel does not support the functions used in the formula. The SEQUENCE and TEXTJOIN functions require Microsoft 365, Excel 2019/2021, or a modern alternative like WPS Office.

How do I remove the inserted commas if I change my mind?

If you need to revert the text, you can use the SUBSTITUTE function to strip out the commas and spaces. For example, =SUBSTITUTE(B1, ", ", "") will remove the comma and space delimiter and restore the continuous string.