How to Insert a Comma After Every Four Characters in Excel
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.

- 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.
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.
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.
Click on a blank cell where you want the formatted, comma-separated text to appear.
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.
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 VBA for Older Excel Versions
Ideal for users running Excel 2016 or older who do not have access to modern functions like TEXTJOIN or SEQUENCE.
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. Open your dataset: Launch WPS Spreadsheet and open the document containing the continuous text you want to format.
- 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. Get instant results: Press Enter. WPS Spreadsheet instantly processes the dynamic array and formats your string with commas exactly where needed.
- 4. Save your work: Click Save. Your perfectly formatted file remains completely compatible with Microsoft Excel formats.

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.




