Add Characters Every X Characters in Excel Cells - Easy Methods
AuthorXiaoyang•Last modified
When working with product codes, serial numbers, phone numbers, ID numbers, or long text strings in Excel, you may need to insert a specific character every fixed number of characters. For example, you may want to convert ABCDEF123456 into ABC-DEF-123-456, or add spaces every 4 digits to make long numbers easier to read.
Excel does not provide a direct built-in button for this task, but you can easily do it with some easy methods. This article will show you several practical methods to add or insert specific characters every X characters in Excel cells.

Add Characters Every X Characters in Excel
The following methods will show you how to quickly insert specific characters every specified number of characters in Excel, helping you easily separate long text, IDs, product codes, or number strings at fixed intervals to make the content more standardized and easier to read.
Method 1: Add Characters Every X Characters with formula
If you are using Excel 365 or Excel 2021, you can use a dynamic array formula to split the text into fixed-length groups and then join them with a specified character.
Enter the following formula into a blank cell:
=TEXTJOIN("-",TRUE,MID(A2,SEQUENCE(ROUNDUP(LEN(A2)/4,0),,1,4),4))
Then press Enter key. Drag the fill handle down to fill the formula to other cells.
How this formula works?
- LEN(A2): Gets the total number of characters in cell A2.
- ROUNDUP(LEN(A2)/4,0): Calculates how many groups are needed. If the last group has fewer than 4 characters, it will still be included.
- SEQUENCE(ROUNDUP(LEN(A2)/4,0),,1,4): Generates the starting positions: 1, 5, 9, 13, and so on.
- MID(A2,SEQUENCE(...),4): Extracts every 4-character group from the text.
- TEXTJOIN("-",TRUE,...): Joins all extracted groups with a hyphen.
Customize the formula
You can change the character and interval as needed.
Add a space every 4 characters:
=TEXTJOIN(" ",TRUE,MID(A2,SEQUENCE(ROUNDUP(LEN(A2)/4,0),,1,4),4))
Add a slash every 2 characters:
=TEXTJOIN("/",TRUE,MID(A2,SEQUENCE(ROUNDUP(LEN(A2)/2,0),,1,2),2))
Use cell references for flexible settings: (This version is more flexible because you can change the inserted character or interval number without editing the formula itself.)
If:
- Original text is in A2,
- Character to insert is in B1,
- Interval number is in C1
=TEXTJOIN($B$1,TRUE,MID(A2,SEQUENCE(ROUNDUP(LEN(A2)/$C$1,0),,1,$C$1),$C$1))
Pros and cons
| Pros | Cons |
|---|---|
| Dynamic result that updates automatically | Only works in Excel 365, Excel 2021, and later versions |
| No VBA required | Formula may be difficult for beginners |
| Easy to copy down for multiple cells | Result is formula-based, not static text |
Method 2: Add Characters Every X Characters with VBA code
If you want to insert a specific character every fixed number of characters in multiple cells and directly output the result, VBA is a good option.
- Hold down the ALT + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.
- Click Insert > Module, and paste the following code in the Module Window.
Sub InsertCharacter()
'Updateby Extendoffice
Dim Rng As Range
Dim InputRng As Range, OutRng As Range
Dim xRow As Integer
Dim xChar As String
Dim index As Integer
Dim arr As Variant
Dim xValue As String
Dim outValue As String
Dim xNum As Integer
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
xRow = Application.InputBox("Number of characters :", xTitleId, Type:=1)
xChar = Application.InputBox("Specify a character :", xTitleId, Type:=2)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set OutRng = OutRng.Range("A1")
xNum = 1
For Each Rng In InputRng
xValue = Rng.Value
outValue = ""
For index = 1 To VBA.Len(xValue)
If index Mod xRow = 0 And index <> VBA.Len(xValue) Then
outValue = outValue + VBA.Mid(xValue, index, 1) + xChar
Else
outValue = outValue + VBA.Mid(xValue, index, 1)
End If
Next
OutRng.Cells(xNum, 1).Value = outValue
xNum = xNum + 1
Next
End Sub
- Press F5 key to run this code. A prompt box will appear, asking you to select the data range where you want to insert a specific character into the text strings. See the screenshot below:

- And click OK, in the following prompt box, please enter the number that you want to insert certain character every after, see screenshot:

- Go on clicking OK, and in the followed prompt box, please enter the certain character that you want to add to the text, see screenshot:

- Click OK button, and choose one cell where you want to output the result in the prompt box, see screenshot:

- Finally, click OK. Excel will insert the specified character every X characters and place the results in the selected output range.

Pros and cons
| Pros | Cons |
|---|---|
| Works in older Excel versions | Requires enabling macros |
| Can process many cells at once | VBA may be difficult for beginners |
| Outputs static results directly | Not dynamic if source data changes |
| Flexible character and interval settings | Macro files need to be saved as .xlsm |
Method 3: Add characters every X characters with User Defined Function
A User Defined Function, also called a UDF, lets you create your own Excel function with VBA. After adding the function, you can use it like a normal worksheet formula.
- Press Alt + F11 to open the VBA editor.
- Click Insert > Module. Copy and paste the following code into the module.
Function InsertEveryX(TextStr As String, InsertChar As String, IntervalNum As Long) As String
Dim i As Long
Dim ResultStr As String
If IntervalNum <= 0 Then
InsertEveryX = TextStr
Exit Function
End If
For i = 1 To Len(TextStr) Step IntervalNum
ResultStr = ResultStr & Mid(TextStr, i, IntervalNum) & InsertChar
Next i
If Len(ResultStr) > 0 Then
ResultStr = Left(ResultStr, Len(ResultStr) - Len(InsertChar))
End If
InsertEveryX = ResultStr
End Function
- Close the VBA editor and return to the worksheet. Use the following formula:
=InsertEveryX(A2,"-",4)
Tip: You can also store the inserted character and interval number in cells.
Then drag the fill handle down to apply the formula to other cells. 
Pros and cons
| Pros | Cons |
|---|---|
| Works like a normal Excel formula | Requires VBA setup |
| Easier to read than a complex formula | Macros must be enabled |
| Reusable in the workbook | Not available in other workbooks unless copied |
| Supports custom characters and intervals | Workbook should be saved as .xlsm |
Method 4: Add characters every X characters with Kutools for Excel
If you do not want to use complex formulas or VBA code, Kutools for Excel provides an easier way to insert characters into cell text. With its text tools, you can quickly add specific characters at fixed positions or apply text-processing operations to multiple cells.
- Select the cells where you want to insert characters. Then, Click Kutools > Text > Add Text.

- In the Add Text dialog box:
- Enter the character you want to insert, such as -, /, or a space into the Text box.
- Under the Add Position section, choose Specify position and enter the positions where the character should be inserted.
- Click OK.

Tip: In this example, I entered 4, 8, 12 in the Specify position box, which means the specific text will be inserted after the 4th, 8th, and 12th characters of each text string.
Now, the specified character has been inserted into the cell values at the specified intervals.
Insert Text into Excel Cells Faster with Kutools
With Kutools for Excel’s Add Text feature, you can quickly insert specific characters, symbols, or text into selected cells without writing complex formulas or VBA code.
Important Notes & Limitations
1. Formula results are dynamic
If you use the formula method, the result will update automatically when the original text changes. This is useful for ongoing worksheets, but the result is still formula-based.
If you need fixed text values, copy the formula results and use: Home > Paste > Paste Values
2. VBA and Kutools usually return static results
VBA and Kutools are better for one-time processing. Once the characters are inserted, the result will not update automatically when the source text changes unless you run the code or tool again.
3. Check whether the last group is shorter
If the text length is not exactly divisible by the interval number, the last group will contain the remaining characters.
4. Empty cells
When the selected range contains blank cells, VBA and Kutools can usually skip them automatically or leave them unchanged. However, if you use formulas, blank cells may return unexpected results or errors. To avoid this, you can wrap the formula with IF or IFERROR to keep blank cells empty.
=IF(A2="","",TEXTJOIN("-",TRUE,MID(A2,SEQUENCE(ROUNDUP(LEN(A2)/4,0),,1,4),4)))
5. Special characters
Most common separators, such as hyphens, commas, spaces, slashes, and dots, can be inserted normally. You can also insert other custom text.
Conclusion
Adding characters every X characters in Excel can make long text strings easier to read, format, and manage. For Excel 365 or Excel 2021 users, the formula method is a flexible and dynamic solution. If you need to process many cells at once, VBA can help you complete the task efficiently. If you want a reusable custom formula, a User Defined Function is a good choice. For users who prefer a simple, visual, and no-code method, Kutools for Excel provides a faster way to handle this type of text formatting task.
In general, use formulas when you want dynamic results, use VBA or UDFs when you need more control, and use Kutools when you want the easiest workflow with fewer manual steps.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
All Kutools add-ins. One installer
Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.
- All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
- One installer, one license — set up in minutes (MSI-ready)
- Works better together — streamlined productivity across Office apps
- 30-day full-featured trial — no registration, no credit card
- Best value — save vs buying individual add-in
Table of contents
- Add Characters Every X Characters in Excel
- Method 1: By formula
- Method 2: By VBA code
- Method 3: By User Defined Function
- Method 4: By Kutools for Excel
- Important Notes & Limitations
- Conclusion
- The Best Office Productivity Tools
Kutools for Excel
Brings 300+ advanced features to Excel
- ⬇️ Free Download
- 🛒 Purchase Now
- 📘 Feature Tutorials
- 🎁 30-Day Free Trial






