• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

Adding Spaces to a Number in Excel - Excel Macro


I have a series of numbers in column E of my spreadsheet that I want to a space after every 2 digits.  

For example, I want to change  21550080140210  in cell E10 to  21 55 00 80 14 02 10 and then continue down the column (E11 to the end) until all numbers have been changed

How do I approach this situation in Excel to create a macro to do this.

Thanks for checking my question out

1 Solution
Saqib Husain, SyedEngineerCommented:
If the numbers are numerical then numberformat the cells as custom format using ## ## ## ## ## ## ## ## ##

If they are text entries then try this macro

Sub splittwos()
    Dim cel As Range, i As Long
    For Each cel In Range("E10:E" & Range("E10").End(xlDown).Row)
        For i = Len(cel) + (Len(cel) + 1) Mod 2 To 1 Step -2
            cel = WorksheetFunction.Replace(cel, i, 0, " ")
        Next i
    Next cel
End Sub
BulldogMikeAuthor Commented:
My data was numeric so this was an easy fix. - Thanks

Look for my next question on how to pull descriptions for these codes from Spreadsheet B into spreadsheet A where the codes reside



Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now