Solved

Separating Words with Caps in Excel

Posted on 2011-03-01
2
203 Views
Last Modified: 2012-05-11
I have a column of words in Excel that don't have spaces in them.
I.e.  ThisSentenceHasManyWords

I want to convert them to look like this:

This Sentence Has Many Words.
Is there a code I can put in a macro to do this?
0
Comment
Question by:ENTPF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35009719
Try this macro - you just need to select the data before running it.
Sub SpaceWords()
   Dim rCell As Range
   Dim strText As String
   Application.ScreenUpdating = False
   With CreateObject("vbscript.regexp")
       .Pattern = "([A-Z])"
       .IgnoreCase = False
       .Global = True
       For Each rCell In Selection
           rCell.Value = Mid$(.Replace(rCell.Value, " $1"), 2)
       Next rCell
   End With
   Application.ScreenUpdating = True
End Sub

Open in new window

0
 
LVL 24

Expert Comment

by:StephenJR
ID: 35009760
rory's solution is much neater than mine, but since I did it I'll post it. A custom formula so you enter in a cell, e.g. =AddSpace(A1)
Function AddSpace(vIn) As String

Dim oRgx As Object, oMatches As Object, i As Long, s As String

With CreateObject("VBScript.RegExp")
    .Global = True
    .IgnoreCase = False
    .Pattern = "[A-Z]{1}[a-z]+"
    Set oMatches = .Execute(vIn)
End With

For i = 0 To oMatches.Count - 1
    s = s & " " & oMatches(i)
Next i

AddSpace = Trim(s)

End Function

Open in new window

0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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…

738 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