Skip to main content

 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
    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 30 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:

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?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

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

Description


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!
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations