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 insert / add space after every x characters in cells?

If you have multiple text strings in a list of worksheet, now, you want to insert space after every 3 or x characters in cells as following screenshot shown. How could you solve this problem in Excel quickly and easily?

doc add space after x characters 1

Insert / Add space after every x characters in cells with VBA code

Insert / Add space after every x characters in cells with Kutools for Excel


arrow blue right bubble Insert / Add space after every x characters in cells with VBA code

Applying the following VBA code, you can quickly insert the space after every n characters for multiple cells at once, please do as follows:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Then click Insert > Module, and paste the following code in the Module window.

VBA code: Insert space after every x characters:

Sub addspace()
'updateby Extendoffice 20151207
    Dim i As Long
    Dim xCell As Range
    Dim xRg As Range
    Dim xTxt As String
    Dim xStr As String
    Dim xUpdate As Boolean
    On Error Resume Next
    xTxt = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
    If xRg Is Nothing Then Exit Sub
    xUpdate = Application.ScreenUpdating
    Application.ScreenUpdating = False
    For Each xCell In xRg
        xStr = xCell.Text
        xTxt = ""
        For i = 1 To Len(xStr) Step 4
            If xTxt = "" Then
                xTxt = Mid(xStr, i, 4)
            Else
                xTxt = Trim(xTxt) & " " & Mid(xStr, i, 4)
            End If
        Next
        xCell = xTxt
    Next
    Application.ScreenUpdating = xUpdate
End Sub

3. Then press F5 key to run this code, and in the prompt box, please select the cells that you want to insert space to, see screenshot:

doc add space after x characters 2

4. And then click OK button, and the spaces have been inserted into the cell contents after every four characters, see screenshots:

doc add space after x characters 3  2 doc add space after x characters 4

Note: In the above code, you can change the number 4 to other number to insert space after. And also you can change the delimiter space to another delimiters in this rule xTxt = Trim(xTxt) & " " & Mid(xStr, i, 4) of the above code.


arrow blue right bubble Insert / Add space after every x characters in cells with Kutools for Excel

Kutools for Excel’s Add Text feature also can help you to solve this problem quickly and easily.

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

After installing Kutools for Excel, please do as follows:( Free Download Kutools for Excel Now! )

1. Select the text strings that you want to insert space.

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

doc add space after x characters 5

3. In the Add Text dialog box, press the space bar once into the Text box, and select the Specify option under the Position, then type the positions that you want to insert the space, see screenshot:

doc add space after x characters 6

4. And then click Ok or Apply button, you will get the result that the spaces have been inserted after every four characters as you need.

Tips: The number of positions in Specify textbox should be separated by commas.

Free Download Kutools for Excel Now!


Related article:

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



Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
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.