|
|

January 11th, 2008
|
 |
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.
|

January 11th, 2008
|
 |
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
|
|
|
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.
|

January 11th, 2008
|
 |
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.
|

January 11th, 2008
|
 |
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
|
|
|
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
|

January 11th, 2008
|
 |
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
|
|
|
Re: Add Space To Text String By Uppercase Lettering
Andy how does the A to Z Work?
|

January 11th, 2008
|
 |
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
|
|
|
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
|

January 11th, 2008
|
 |
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
|
|
|
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
|

January 11th, 2008
|
 |
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
|
|
|
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"
strLetter = "T"
If strLetter >= "A" And strLetter <= "Z" Then
MsgBox " Upper case " & strLetter
Else
MsgBox "Something else"
End If
End Sub
__________________
Cheers
Andy
|

January 11th, 2008
|
|
|
|
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
|

January 11th, 2008
|
 |
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.
|
All times are GMT +9. The time now is 21:37.
|