Solved

Separating Words with Caps in Excel

Posted on 2011-03-01
2
198 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now