Excel 2010-Now
Excel 2007
Excel 2003
Tips & Tricks
Excel Forum
Course Index CIG Excel Book
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Excel Tip: Breaking Up Text Strings    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Excel Tip Breaking Up Text Strings
Alex Hedley 
           
14 years ago
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

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Excel Tip: Breaking Up Text Strings.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/9/2026 2:29:30 AM. PLT: 0s