Add Space To Each Uppercase Letter In Text - Excel Help & Excel Macro Help
SEARCH ENTIRE SITE LOADING..

Excel Help & Excel Best Practices Forums

 

Proudly Affiliated With: Intelligent Converters & AnalyserXL <Affiliate Program & ExcelUser Affiliate>

 

SPECIALS PAGE FOR BARGAINS | FREE EXCEL TRAINING | FREE CUSTOM FUNCTIONS ADD-IN


Go Back Excel Help & Excel Macro Help > HELP FORUMS > EXCEL HELP
HOME Register Forum Help Calendar Search For Today's Posts Mark Forums Read

Reply

Add Space To Each Uppercase Letter In Text

ANSWERS TO SIMILAR QUESTIONS
Remove All Text Left Of Space And The SpaceAdd Space Between Text In CodeForcing Uppercase when typing in a Userform text box?Text Width? Space(X)...countif text but not space



Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com

Create Excel dashboards quickly with Plug-N-Play reports.


 
Thread Tools Search this Thread
Old January 11th, 2008
SerenityNetwork's Avatar
SerenityNetwork SerenityNetwork is offline
Senior Member
 
I'm a Spammer: NO
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 8th February 2005
English is 1st Language: Yes
Location: Texas
Posts: 197 -- Threads: 44
Add Space To Each Uppercase Letter In Text

I import a CSV file into Excel where the column title row has column titles that are just one long text string, without any spacing between the words. For example:
CompanySiteDescription
CompanySiteExternalSystemID
IssueNumber

I would like a method (formula or macro) that would add a space-character before each uppercase letter (that's not the first letter in the string or an uppercase letter that directly follows another upper case letter). Thus:
CompanySiteDescription becomes Company Site Description
CompanySiteExternalSystemID becomes Company Site External System ID
IssueNumber becomes Issue Number

Any code or examples on this will be greatly appreciated.

Thanks,
Andrew
__________________
Chaos, panic, and disorder. My work here is done.
Print [Post / Thread] Reply With Quote
Old January 11th, 2008
shg's Avatar
shg shg is offline
OzMVP
 
I'm a Spammer:
MS Office Version: 2003, 2007
Op System: Windows XP
Assumed Experience: A fair amount of Excel and VBA
Join Date: 12th September 2006
English is 1st Language: Yes
Location: Texas
Posts: 4,120 -- Threads: 39
Re: Add Space To Text String By Uppercase Lettering

Write a function that loops through the string and uses a case statement; if the character is "A" to "Z", put a space followed by the character to the output string; anything else, put the character in the output string.
__________________
You name your kids--why not your variables? Use Option Explicit.
Print [Post / Thread] Reply With Quote
Old January 11th, 2008
SerenityNetwork's Avatar
SerenityNetwork SerenityNetwork is offline
Senior Member
 
I'm a Spammer: NO
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 8th February 2005
English is 1st Language: Yes
Location: Texas
Posts: 197 -- Threads: 44
Re: Add Space To Text String By Uppercase Lettering

Thank you.

If you had provided the tip on using a formula then I could probably figure it out. I'm generally handy at formulas. But I'm not handy at VBA. I'll try to give it a whirl in the next few days. I imagine that I'll have questions.

Thanks again,
Drew
__________________
Chaos, panic, and disorder. My work here is done.
Print [Post / Thread] Reply With Quote
Old January 11th, 2008
Andy Pope's Avatar
Andy Pope Andy Pope is offline
OzMVP (Roobarb)
 
I'm a Spammer:
MS Office Version: 2000/2003/2007
Op System: Vista Business
Assumed Experience: Ever growing
Join Date: 7th March 2003
English is 1st Language: Yes
Location: Essex, England
Posts: 11,320 -- Threads: 32
Re: Add Space To Text String By Uppercase Lettering

Here is a UDF.

B1: =splitcameltext(A1)

Code

VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Function SplitCamelText(TextToSplit As Variant, Optional Delimiter As Variant = " ") As Variant Dim lngIndex As Long Dim strText As String Dim blnPreviousLetterUpper As Boolean On Error Goto Err_SplitCamelText strText = TextToSplit lngIndex = 2 Do While lngIndex <= Len(strText) Select Case Mid(strText, lngIndex, 1) Case "A" To "Z" If Not blnPreviousLetterUpper Then strText = Left(strText, lngIndex - 1) & Delimiter & Mid(strText, lngIndex) End If blnPreviousLetterUpper = True Case Else blnPreviousLetterUpper = False End Select lngIndex = lngIndex + 1 Loop SplitCamelText = strText Exit Function Err_SplitCamelText: SplitCamelText = XlCVError.xlErrValue Exit Function End Function
__________________

Cheers
Andy

Print [Post / Thread] Reply With Quote
Old January 11th, 2008
Craig Ottley's Avatar
Craig Ottley Craig Ottley is offline
Jedi Master
 
I'm a Spammer: NO
MS Office Version: 2003 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 15th March 2007
English is 1st Language: Yes
Location: Milton Keynes
Posts: 1,209 -- Threads: 10
Re: Add Space To Text String By Uppercase Lettering

Andy how does the A to Z Work?
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old January 11th, 2008
Andy Pope's Avatar
Andy Pope Andy Pope is offline
OzMVP (Roobarb)
 
I'm a Spammer:
MS Office Version: 2000/2003/2007
Op System: Vista Business
Assumed Experience: Ever growing
Join Date: 7th March 2003
English is 1st Language: Yes
Location: Essex, England
Posts: 11,320 -- Threads: 32
Re: Add Space To Text String By Uppercase Lettering

The help file says

Quote:
You also can specify ranges and multiple expressions for character strings. In the following example, Case matches strings that are exactly equal to everything, strings that fall between nuts and soup in alphabetic order, and the current value of TestItem:

Case "everything", "nuts" To "soup", TestItem


Basically it allows all characters between A and Z
__________________

Cheers
Andy

Print [Post / Thread] Reply With Quote
Old January 11th, 2008
Craig Ottley's Avatar
Craig Ottley Craig Ottley is offline
Jedi Master
 
I'm a Spammer: NO
MS Office Version: 2003 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 15th March 2007
English is 1st Language: Yes
Location: Milton Keynes
Posts: 1,209 -- Threads: 10
Re: Add Space To Text String By Uppercase Lettering

handy tip to know... all this time i've been looping through an array of charactors
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old January 11th, 2008
Andy Pope's Avatar
Andy Pope Andy Pope is offline
OzMVP (Roobarb)
 
I'm a Spammer:
MS Office Version: 2000/2003/2007
Op System: Vista Business
Assumed Experience: Ever growing
Join Date: 7th March 2003
English is 1st Language: Yes
Location: Essex, England
Posts: 11,320 -- Threads: 32
Re: Add Space To Text String By Uppercase Lettering

works with a IF test as well

VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub X() Dim strLetter As String strLetter = "t" ' fails strLetter = "T" ' passes If strLetter >= "A" And strLetter <= "Z" Then MsgBox " Upper case " & strLetter Else MsgBox "Something else" End If End Sub
__________________

Cheers
Andy

Print [Post / Thread] Reply With Quote
Old January 11th, 2008
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
jindon jindon is offline
Long Term Member
 
I'm a Spammer:
MS Office Version: 2002(XP)
Op System: Windows XP
Assumed Experience: What is Excel?
Join Date: 19th July 2004
English is 1st Language: No
Posts: 1,861 -- Threads: 0
Re: Add Space To Text String By Uppercase Lettering

UDF
=seren(A1)
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Function seren(txt As String) As String With CreateObject("vbscript.regexp") .Pattern = "([A-Z])" .Global = True seren = Trim(.replace(txt, Chr(32) & "$1")) End With End Function
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old January 11th, 2008
SerenityNetwork's Avatar
SerenityNetwork SerenityNetwork is offline
Senior Member
 
I'm a Spammer: NO
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 8th February 2005
English is 1st Language: Yes
Location: Texas
Posts: 197 -- Threads: 44
Re: Add Space To Each Uppercase Letter In Text

Oh, wow! Thank you everyone. I was just updating my profile to better describe my VBA abilities (per shg's suggestion) and hadn't seen all the code samples you all have provided.

I don't have time to try them tonight, as I'm still working a late night project for my job, but I will get to it soon.

Thank you again. I'm very grateful.

Sincerely,
Andrew
__________________
Chaos, panic, and disorder. My work here is done.
Print [Post / Thread] Reply With Quote
Reply Lifetime Upgrade To Ad Free Styles

   « PREVIOUS Format Cell To White With Gridlines Showing || Populate Data From Another Sheet With Criteria NEXT »
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 21:37.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ozgrid is Not Associated With Microsoft. Ozgrid Retains the Rights to ALL Posts and Threads