ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert space before CAPITAL letters (https://www.excelbanter.com/excel-programming/419838-insert-space-before-capital-letters.html)

althea@ads-ny

Insert space before CAPITAL letters
 
I have some very large files where some columns have the text without any
spaces. However they are using CAPS for all first letters. For example:

TheBookStore
WalmartDiscountStores

Is there a formula or macro that can add a space before every CAP (PROPER)
letter so that it will read:

The Book Store
Walmart Discount Stores

Thanks,
Althea


Daniel.C[_2_]

Insert space before CAPITAL letters
 
Try :
Sub test()
Dim c As Range, i As Long, txt As String
For Each c In Range("A1", [A65000].End(xlUp))
txt = ""
For i = 1 To Len(c.Value)
If Mid(c, i, 1) = UCase(Mid(c, i, 1)) Then
txt = txt & " " & Mid(c, i, 1)
Else
txt = txt & Mid(c, i, 1)
End If
Next i
c.Value = Right(txt, Len(txt) - 1)
Next c
End Sub

Regards.
Daniel

I have some very large files where some columns have the text without any
spaces. However they are using CAPS for all first letters. For example:

TheBookStore
WalmartDiscountStores

Is there a formula or macro that can add a space before every CAP (PROPER)
letter so that it will read:

The Book Store
Walmart Discount Stores

Thanks,
Althea




Chip Pearson

Insert space before CAPITAL letters
 
Try code like the following. Select the cells you want to change and
then run the code:

Sub AAA()
Dim R As Range
Dim N As Long
Dim S As String
If TypeOf Selection Is Excel.Range Then
For Each R In Selection.Cells
If R.HasFormula = False Then
If R.HasArray = False Then
S = R.Text
For N = Asc("A") To Asc("Z")
S = Replace(S, Chr(N), " " & Chr(N))
Next N
S = LTrim(S)
R.Value = S
End If
End If
Next R
End If
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 11 Nov 2008 04:51:01 -0800, althea@ads-ny
wrote:

I have some very large files where some columns have the text without any
spaces. However they are using CAPS for all first letters. For example:

TheBookStore
WalmartDiscountStores

Is there a formula or macro that can add a space before every CAP (PROPER)
letter so that it will read:

The Book Store
Walmart Discount Stores

Thanks,
Althea


althea@ads-ny

Insert space before CAPITAL letters
 
Chip,

You are a God-send!! Worked like a charm. I have thousands of lines in
many files and many columns and this will save me hours!!!

Thanks again!
Althea

"Chip Pearson" wrote:

Try code like the following. Select the cells you want to change and
then run the code:

Sub AAA()
Dim R As Range
Dim N As Long
Dim S As String
If TypeOf Selection Is Excel.Range Then
For Each R In Selection.Cells
If R.HasFormula = False Then
If R.HasArray = False Then
S = R.Text
For N = Asc("A") To Asc("Z")
S = Replace(S, Chr(N), " " & Chr(N))
Next N
S = LTrim(S)
R.Value = S
End If
End If
Next R
End If
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 11 Nov 2008 04:51:01 -0800, althea@ads-ny
wrote:

I have some very large files where some columns have the text without any
spaces. However they are using CAPS for all first letters. For example:

TheBookStore
WalmartDiscountStores

Is there a formula or macro that can add a space before every CAP (PROPER)
letter so that it will read:

The Book Store
Walmart Discount Stores

Thanks,
Althea




All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com