Solved

Adding Spaces to a Number in Excel - Excel Macro

Posted on 2012-04-09
2
411 Views
Last Modified: 2012-04-09
Hi

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

Mike
0
Comment
Question by:BulldogMike
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 37823545
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
0
 

Author Closing Comment

by:BulldogMike
ID: 37823872
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

Thanks

Mike
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TSQL previous 5 24
Most Consistent Performer 4 20
Help with Excel formula 6 38
Excel range I cannot find 8 0
This article will show you how to use shortcut menus in the Access run-time environment.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now