Insert space before upper case letter

zep

New Member
Joined
Nov 28, 2006
Messages
17
Hey guys,

Since my last post, I have ruined, and saved a massive sheet I was working on. I think quite Excel and ruined my chanced of fixing my error.

I ran a script to pull the spaces out of every fourth cell in a column except it ran on all cells and before I realised it all my words were crammed together.

The only way I can think to fix this is my creating a script which inserts a space before each capital letter (as most are business names or addresses).

If anyone could help here, that be excellent.

Cheers

(I should really learn to write macros myself)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
Hi zep

This code inserts a space before each capital letter in column A:
Code:
Sub InsertSpace()
Dim rRng As Range, rCell As Range

Set rRng = Range("A1", Range("A" & Rows.Count).End(xlUp))

With CreateObject("vbscript.regexp")
    .Pattern = "([A-Z])"
    .Global = True
    
    For Each rCell In rRng
        rCell = .Replace(rCell, " $1")
    Next rCell
End With
End Sub

Hope this helps
PGC
 

Forum statistics

Threads
1,181,102
Messages
5,928,063
Members
436,586
Latest member
latintxn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top