Excel 2010-2019
Excel 2007
Excel 2003
Tips & Tricks
Excel Forum
Course Index CIG Excel Book
 
Home   News   Courses   Tips   Templates   Forums   Help   Order   Contact   Logon  
 
 
Excel Tip: Breaking Up Text Strings
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   8/18/2010 5:47:12 PM

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

Enjoy.

Excel Tip Breaking Up Text Strings Link 
Alex Hedley    
8/12/2012
Hi Ritesh,


How is your VBA?

A quick google search found the following:
[http://www.pcreview.co.uk/forums/split-astring-using-capital-letter-identifier-t3855968.html]

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.

'Usage
=SplitWords(A1)

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)
  Next
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.

(http://www.asciitable.com/)

Function splitcap(wholestr)
  splitstr = ""
  For i = 1 To Len(wholestr)
    currchr = Mid(wholestr, i, 1)
    splitstr = splitstr & IIf(Asc(currchr) < 91 And i > 1, " ", "") &
    currchr
  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
  Next
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

Regards
Alex
Add a Reply

Show All Posts

 

Post Your Comments
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 

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

6/5/2020Excel Worksheet Change VBA
5/25/2020Excel Expert 11 Student Forum
5/23/2020Excel XLOOKUP Function
5/20/2020Excel Expert Level 11
5/20/2020Excel Expert 11 Outline
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
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search The Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

YouTube Channel    LinkedIn

Blog RSS Feed   
Keywords: excel tips text sttrings find len left right  PermaLink