Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to add / insert certain character every x characters into cells?

Supposing, I have a list of text strings that I want to insert dashes or any other separators after every four characters into cells to get the following screenshot result. There are too many cells needed to insert the certain character, are there any quick ways to insert dashes every four character in Excel?

Insert certain character every x characters into cell with VBA code

Insert certain character every x characters into cell with Kutools for Excel

doc insert every x character 1


Add specific character before / after / certain position of the text string:

Kutools for Excel’s Add Text utility can help you to add specific character or letter before or after all cells, at the same time it also can insert the character among the certain position of the text strings.

doc insert every x character 11

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


Insert certain character every x characters into cell with VBA code


You can apply the following VBA code to insert a specific character after every four characters into cells, please do as follows:

1. Hold down the ALT + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Insert certain character every x characters into cell

Sub InsertCharacter()
'Updateby20150813
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

3. Then press F5 key to run this code, and a prompt box will pop out to remind you to select the data range that you want to insert certain character within the text strings, see screenshot:

doc insert every x character 2

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

doc insert every x character 3

5. 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:

doc insert every x character 4

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

doc insert every x character 5

7. At last, click OK, the certain character has been inserted into each text string every four characters, see screenshot:

doc insert every x character 6


Insert certain character every x characters into cell with Kutools for Excel

The above code maybe somewhat difficult for most Excel beginner, here, I can introduce a handy tool -- Kutools for Excel, with its Add Text feature, you can quickly add a specific text or character before, after or the certain positions of the cell value.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days. 

If you have installed Kutools for Excel, please do as follows:

1. Select the data range that you want to insert a specific character.

2. Then click Kutools > Text > Add Text, see screenshot:

doc insert every x character 7 7

3. In the Add Text dialog box, specify a character that you want to insert in the Text box, and then choose Specify from the Position section, in the text box, enter the positions that you want to insert the character after, at the same time, you can preview the result at the right pane, see screenshot:

doc insert every x character 8

Tips: Here I type 4,8,12 in the textbox of Specify which indicate to insert the specific text after the 4th, 8th and 12th characters of the text string.

4. Then click Ok or Apply button, the specified character has been inserted into the cell values at specific positions.

doc insert every x character 9  2 doc insert every x character 10

Click to know more details about this Add Text utility.

Download and free trial Kutools for Excel Now !


Demo: Insert certain character every x characters into cell with Kutools for Excel

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.