+ Reply to Thread
Results 1 to 12 of 12

VBA issue - trying to separate words with CAPITALS from Proper words

  1. #1
    Registered User
    Join Date
    05-23-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    14

    VBA issue - trying to separate words with CAPITALS from Proper words

    Function issue.xlsm
    Hello guys,

    I have the following problem: A spreadsheet with one column of names like Ada Milea Beatrice GUINESS DAVIS. That is one person's name. Proper words are first name, CAPITAL words are last name. The lenght of the first name can very from one word to five words, the same for last name.
    Assuming these names are in column A, I want in the B column the last name and in C column the first name.

    A B C
    Ada Milea Beatrice GUINESS DAVIS GUINESS DAVIS Ada Milea Beatrice
    Jean-Christophe BASSON-LARBI BASSON-LARBI Jean-Christophe
    ....

    What I have so far are two functions: One that removes proper words and leaves the capital words and one that removes the capitals and leaves the proper words. At first glance, that is all I need. But no, I came across an issue inside my RemoveCaps function. When the CAPS name has "-" included, the function does not work. I have attached a sample file with the codes and examples.

    Can anyone help me out?

    Thanks
    Last edited by Eagle29; 05-24-2013 at 03:04 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    no attachment found, insert please also desired result
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    05-23-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Desired result:
    A
    Ada Milea Beatrice GUINESS DAVIS
    Jean-Christophe BASSON-LARBI

    B
    GUINESS DAVIS
    BASSON-LARBI

    C
    Ada Milea Beatrice
    Jean-Christophe
    Last edited by Eagle29; 05-24-2013 at 03:11 AM.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    can I see your code ?

  5. #5
    Registered User
    Join Date
    05-23-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Thought it was already there... Anyways, here are the functions:
    ----------------------- first function -------------------

    Option Explicit
    Option Compare Binary

    Function RemoveCaps(c As Range)
    Dim Individual() As String, keeper As String
    Dim i As Integer, j As Integer, k As Integer
    Dim allCaps As Boolean

    Individual = Split(c)
    k = 0
    For i = 0 To UBound(Individual)
    allCaps = True
    For j = 1 To Len(Individual(i))
    If Not Mid(Individual(i), j, 1) Like "[A-Z]" Then
    allCaps = False
    keeper = " " & keeper & Individual(i) & " "
    Exit For
    End If
    Next j
    Next i
    RemoveCaps = Trim(keeper)
    End Function

    ------------------------------------------------ second function ---------------------------


    Option Explicit
    Option Compare Binary

    Function RemoveProper(c As Range)
    Dim Individual() As String, keeper As String
    Dim i As Integer, j As Integer, k As Integer, m As Integer
    Dim allCaps As Boolean

    Individual = Split(c)
    k = 0
    m = 0
    For i = 0 To UBound(Individual)
    allCaps = False
    For j = 1 To Len(Individual(i))
    If Not Mid(Individual(i), j, 1) Like "[A-Z]" Then
    If Not Mid(Individual(i), j, 1) Like "-" Then
    allCaps = True
    m = m + 1
    Exit For
    End If
    End If
    Next j
    Next i
    For i = m To UBound(Individual)
    allCaps = False
    For j = 1 To Len(Individual(i))
    If Mid(Individual(i), j, 1) Like "[A-Z]" Then
    allCaps = True
    keeper = " " & keeper & Individual(i) & " "
    End If
    Exit For
    Next j
    Next i
    RemoveProper = Trim(keeper)
    End Function

  6. #6
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Try this

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Another one...

    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Try
    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Nice jindon.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Thanks....

  11. #11
    Registered User
    Join Date
    05-23-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    Thanks guys, but still doesn't work for a particular case:
    Jean-Christophe BASSON-LARBI


    If the name with capital letters has a "-", it returns all the name. If I replace the - with a space, it works just fine. So, how can we include the "-" in the [A-Z] range?

  12. #12
    Registered User
    Join Date
    05-23-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: VBA issue - trying to separate words with CAPITALS from Proper words

    My bad. Thanks a lot guys. jindon's code works just perfect. It was an error on my end.

+ 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