Excel 2010/2013
Excel 2007
Excel 2003
Tips & Tricks
Excel Forum
Course Index CIG Excel Book
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  

News      User Comments     History     Notify Me

8/18/2010 5:47:12 PM
Excel Tip: Breaking Up Text Strings
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

Since I'm back in the groove making videos, I posted a short 5 minute Excel Tip on breaking up text strings.

Ever get a sheet full of names like "Joe Smith" and you need to break them up into first name, last name in separate columns? I'll show you how in this tutorial.

  - Excel Tip: Breaking Up Text Strings


Permanent Link
Keywords: excel tips text sttrings find len left right
Post Reply

Excel Tip Breaking Up Text Strings Comment from Alex Hedley @ 8/12/2012
Hi Ritesh,

How is your VBA?

A quick google search found the following:

The first loops through the word, checking if the letter it is looking at is an Uppercase letter [UCase()] and if so adds a space between it.


Function SplitWords(strData) As String
  Dim intTemp As Integer
  SplitWords = Left(strData, 1)
  For intTemp = 2 To Len(Trim(strData))
    If Mid(strData, intTemp, 1) = UCase(Mid(strData, _
      intTemp, 1)) Then SplitWords = SplitWords & " "
      SplitWords = SplitWords & Mid(strData, intTemp, 1)
End Function


The next checks the ASCII value [Asc()]. If it is in the range of an Uppercase letter (A - 65, Z - 90) split it.


Function splitcap(wholestr)
  splitstr = ""
  For i = 1 To Len(wholestr)
    currchr = Mid(wholestr, i, 1)
    splitstr = splitstr & IIf(Asc(currchr) < 91 And i > 1, " ", "") &
  Next i
  splitcap = splitstr
End Function


This one uses string matching

Function SplitOnCaps(S As String) As String
  Dim X As Long
  SplitOnCaps = S
  For X = Len(SplitOnCaps) To 2 Step -1
    If Mid(SplitOnCaps, X, 1) Like "[A-Z]" Then
      SplitOnCaps = Left(SplitOnCaps, X - 1) & " " & Mid(SplitOnCaps, X)
    End If
End Function


Will there only be ever 1 uppercase to split on? This will do it for any, an example was "FirstnameMiddlenameLastname"

Option Explicit
Function SplitOnCaps(s As String) As String
  Dim re As Object
  Set re = CreateObject("vbscript.regexp")
  re.Global = True
  re.Pattern = "([a-z])([A-Z])"
  SplitOnCaps = re.Replace(s, "$1 $2")
End Function

Each uses a different method and is useful for showing how different in built functions work.

I haven't tested these but the appear to be fine, many thanks to the other guys in the forum for writing this, saved me doing it :p

Show Just This Thread        Post Reply
Excel Tip Breaking Up Text Strings Comment from ritesh @ 8/10/2012
i want space in one single line ,
eg - ChrisTalbert  = Chris Talbert.
ChristensenAl = Christensen Al.
ChristensenJennifer = Christensen Jennifer.
Show Just This Thread        Post Reply
want to learn Comment from shoby @ 11/27/2010
want to learn excel.

Reply from Richard Rost:

Great. You've come to the right place, then. :)
Show Just This Thread        Post Reply

Add Your Comments or Subscribe
If you just want to subscribe to get email updates when the News is updated, then enter your name and email address and check the Notify Me box below. If you would optionally like to add your comments below to be posted, they are welcome.
  Your Name:  Required
  Your Email:  NOT Public


Sorry about this step. It's just to keep the spam bots away:
  Verify: What is 7+2:
  Notify me when the News is updated.
  Remember Me for my next comments
Please do not use this form for Customer Service inquiries! If you have questions about your account, shipping info, courses you've ordered, need passwords, etc. please use the Customer Service Center instead.

I value your comments. They will be displayed on this page (above). Your name will be displayed, but your email address will not be.
As always, I promise to never give away your personal information to anyone else, ever.

NOTE: If you don't leave your name and email address, DON'T expect a reply. I can't promise a personal reply to everyone who posts here. I TRY my best, but I cannot guarantee it. If you don't leave your real name and email address, I won't even bother. I usually just hit DELETE. -Richard



You may want to read these articles from the 599CD News:

5/4/2014Microsoft Access Expert 20
3/5/2013Excel Tip: Price Markups
2/3/2013Signed Copies of my Excel Book
9/27/2012Excel Expert 10 Handbook Ready
9/18/2012Two New Excel Tips: Date/Time Differences
6/20/2012Excel Tip: Sum Cells Between Two Values
6/16/2012New Excel Tip: Paste Link
3/26/2012Excel Tip: 2D Matrix Lookups
11/18/2011Dashboards in Excel
10/6/2011Excel Expert 11 On Hold

Visual Basicindex
Account Login
Online Theater
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Live Chat
Customer Support
WalkThru Tutorials
Consulting Services
About Us
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Gift CDs
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP