+ Reply to Thread
Results 1 to 13 of 13

Separating words in a single cell

  1. #1
    Registered User
    Join Date
    06-15-2006
    Posts
    7

    Unhappy Separating words in a single cell

    Hello there. This is my first post here, I hope this question is not too stupid, but I have no idea on how to do it...:

    I have a list of names like this:
    JohnSmith

    and I need to turn it into this:
    John Smith

    Is there a way to do it? I imagine the way is to ask Excel to include a space between the capital letters, but I don't know how to do it.

    Thanks!

  2. #2
    Ron Rosenfeld
    Guest

    Re: Separating words in a single cell

    On Thu, 15 Jun 2006 11:11:02 -0500, ibere
    <[email protected]> wrote:

    >
    >Hello there. This is my first post here, I hope this question is not too
    >stupid, but I have no idea on how to do it...:
    >
    >I have a list of names like this:
    >JOHNSMITH
    >
    >and I need to turn it into this:
    >JOHN SMITH
    >
    >Is there a way to do it? I imagine the way is to ask Excel to include a
    >space between the capital letters, but I don't know how to do it.
    >
    >Thanks!


    How do you know that

    JOHNSMITH should be JOHN SMITH and not JOHNS MITH?


    --ron

  3. #3
    Bob Phillips
    Guest

    Re: Separating words in a single cell

    They are all capitals. If you don't have some sort of rule, capitals, or a
    space between, it is impossible.

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "ibere" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hello there. This is my first post here, I hope this question is not too
    > stupid, but I have no idea on how to do it...:
    >
    > I have a list of names like this:
    > JOHNSMITH
    >
    > and I need to turn it into this:
    > JOHN SMITH
    >
    > Is there a way to do it? I imagine the way is to ask Excel to include a
    > space between the capital letters, but I don't know how to do it.
    >
    > Thanks!
    >
    >
    > --
    > ibere
    > ------------------------------------------------------------------------
    > ibere's Profile:

    http://www.excelforum.com/member.php...o&userid=35455
    > View this thread: http://www.excelforum.com/showthread...hreadid=552319
    >




  4. #4
    Registered User
    Join Date
    06-15-2006
    Posts
    7
    Bob, thanks.

    I'm writing in the forum and I put the words in bold, so I think it turnet into all capitals in the usenet group, but all names are in the format like JohnSmith.

  5. #5
    Bob Phillips
    Guest

    Re: Separating words in a single cell

    OK, try this

    =LEFT(A1,MIN(IF(CODE(MID(A1,ROW(INDIRECT("2:"&LEN(A1))),1))<97,ROW(INDIRECT(
    "2:"&LEN(A1)))))-1)
    &" "&
    MID(A1,MIN(IF(CODE(MID(A1,ROW(INDIRECT("2:"&LEN(A1))),1))<97,ROW(INDIRECT("2
    :"&LEN(A1))))),99)

    which is an array formula, it should be committed with Ctrl-Shift-Enter, not
    just Enter.

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "ibere" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Bob, thanks.
    >
    > I'm writing in the forum and I put the words in bold, so I think it
    > turnet into all capitals in the usenet group, but all names are in the
    > format like JohnSmith.
    >
    >
    > --
    > ibere
    > ------------------------------------------------------------------------
    > ibere's Profile:

    http://www.excelforum.com/member.php...o&userid=35455
    > View this thread: http://www.excelforum.com/showthread...hreadid=552319
    >




  6. #6
    Ardus Petus
    Guest

    Re: Separating words in a single cell

    Create an UDF (User Defined Function) in a module with following code:

    '----------------------------------------------------
    Function FirstLast(sText As String) As String
    Dim re As RegExp
    If re Is Nothing Then
    Set re = New RegExp
    re.Pattern = "([A-Z][a-z]*)([A-Z][a-z]*)"
    re.IgnoreCase = False
    re.Global = True
    End If

    FirstLast = re.Replace(sText, "$1 $2")
    End Function
    '---------------------------------------------------------------------

    Add a reference to Microsoft VBScripr Regular Expressions 1.0

    Enter following formula in worksheet:

    =FirstLast(A1)

    That should do it!

    Cheers,
    --
    AP

    "ibere" <[email protected]> a écrit dans le
    message de news: [email protected]...
    >
    > Bob, thanks.
    >
    > I'm writing in the forum and I put the words in bold, so I think it
    > turnet into all capitals in the usenet group, but all names are in the
    > format like JohnSmith.
    >
    >
    > --
    > ibere
    > ------------------------------------------------------------------------
    > ibere's Profile:
    > http://www.excelforum.com/member.php...o&userid=35455
    > View this thread: http://www.excelforum.com/showthread...hreadid=552319
    >




  7. #7
    Registered User
    Join Date
    06-15-2006
    Posts
    7
    Ardus,
    I tried to use the code you sent, but a message saying "User-defined type not defined" appears, do you know what can I be doing wrong? Thanks!
    Last edited by ibere; 06-15-2006 at 02:23 PM.

  8. #8
    Ron Rosenfeld
    Guest

    Re: Separating words in a single cell

    On Thu, 15 Jun 2006 11:59:39 -0500, ibere
    <[email protected]> wrote:

    >
    >Bob, thanks.
    >
    >I'm writing in the forum and I put the words in bold, so I think it
    >turnet into all capitals in the usenet group, but all names are in the
    >format like JohnSmith.


    Download and install Longre's free morefunc.xll add-in from
    http://xcell05.free.fr


    Then use this formula:

    =REGEX.SUBSTITUTE(A1,"([a-z])([A-Z])","[1] [2]")

    It will place a <space> between every pair in the string that is characterized
    by a non-cap letter followed by a capitalized letter.

    So in addition to

    JohnSmith --> John Smith

    it will also do

    JohnFranklinSmith --> John Franklin Smith
    --ron

  9. #9
    Bob Phillips
    Guest

    Re: Separating words in a single cell

    You didn't set the reference as suggested?

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "ibere" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Ardus,
    > I tried to use the code you sent, but a message saying "User-defined
    > tyo not defined" appears, do you know what can I be doing wrong?
    > Thanks!
    >
    >
    > --
    > ibere
    > ------------------------------------------------------------------------
    > ibere's Profile:

    http://www.excelforum.com/member.php...o&userid=35455
    > View this thread: http://www.excelforum.com/showthread...hreadid=552319
    >




  10. #10
    Ron Rosenfeld
    Guest

    Re: Separating words in a single cell

    On Thu, 15 Jun 2006 11:11:02 -0500, ibere
    <[email protected]> wrote:

    >
    >Hello there. This is my first post here, I hope this question is not too
    >stupid, but I have no idea on how to do it...:
    >
    >I have a list of names like this:
    >JOHNSMITH
    >
    >and I need to turn it into this:
    >JOHN SMITH
    >
    >Is there a way to do it? I imagine the way is to ask Excel to include a
    >space between the capital letters, but I don't know how to do it.
    >
    >Thanks!


    Just as an addition to my previous post,

    =REGEX.SUBSTITUTE(A1,"([A-Z])"," [1]",2)

    will place a space before every capital letter except the first one.

    So:

    JohnSmith John Smith
    JohnFranklinSmith John Franklin Smith
    JohnFSmith John F Smith
    JohnF.Smith John F. Smith


    --ron

  11. #11
    Ron Rosenfeld
    Guest

    Re: Separating words in a single cell

    On Thu, 15 Jun 2006 19:22:29 +0200, "Ardus Petus" <[email protected]>
    wrote:

    >Create an UDF (User Defined Function) in a module with following code:
    >
    >'----------------------------------------------------
    >Function FirstLast(sText As String) As String
    > Dim re As RegExp
    > If re Is Nothing Then
    > Set re = New RegExp
    > re.Pattern = "([A-Z][a-z]*)([A-Z][a-z]*)"
    > re.IgnoreCase = False
    > re.Global = True
    > End If
    >
    > FirstLast = re.Replace(sText, "$1 $2")
    >End Function
    >'---------------------------------------------------------------------


    Slight modification to put a <space> before every capital except the first:

    ===========================================
    Function FirstLast(sText As String) As String
    Dim re As RegExp
    If re Is Nothing Then
    Set re = New RegExp
    re.Pattern = "([A-Z])"
    re.IgnoreCase = False
    re.Global = True
    End If

    FirstLast = Trim(re.Replace(sText, " $1"))
    End Function
    ==============================================
    --ron

  12. #12
    Kathrine J Wathne
    Guest

    Re: Separating words in a single cell

    Try using this from the menu:

    Data - Text to columns
    Fixed width - and then pull the line into the middle of johnsmith before you
    continue. It will separate into 2 colums etc.


    "ibere" <[email protected]> skrev i melding
    news:[email protected]...
    >
    > Hello there. This is my first post here, I hope this question is not too
    > stupid, but I have no idea on how to do it...:
    >
    > I have a list of names like this:
    > JOHNSMITH
    >
    > and I need to turn it into this:
    > JOHN SMITH
    >
    > Is there a way to do it? I imagine the way is to ask Excel to include a
    > space between the capital letters, but I don't know how to do it.
    >
    > Thanks!
    >
    >
    > --
    > ibere
    > ------------------------------------------------------------------------
    > ibere's Profile:
    > http://www.excelforum.com/member.php...o&userid=35455
    > View this thread: http://www.excelforum.com/showthread...hreadid=552319
    >




  13. #13
    Registered User
    Join Date
    01-24-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Question Re: Separating words in a single cell

    Hi all,

    Thanks for all your work on this thread. I am trying to utilize this VBA to further edit a string field. There are exceptions to the formatting and I was wondering if anymore with more knowledge of RegEx would be able to help me include those exceptions.

    For example:
    I would like to make this: C5_6D_AmpleLength_12Months_toCompleteAAAOnlineClass look like:
    C5_6D_Ample Length_12 Months_to Complete AAA Online Class

    The code I have right now looks like:

    Function FirstLast(sText As String) As String
    Dim re As RegExp
    If re Is Nothing Then
    Set re = New RegExp
    re.Pattern = "([A-Z])"
    re.IgnoreCase = False
    re.Global = True
    End If

    FirstLast = Trim(re.Replace(sText, " $1"))
    End Function

    Any ideas?

    Thanks for your help in advance!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1