Results 1 to 2 of 2

Thread: Reorder List of Names with Capitalized Last Names

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Reorder List of Names with Capitalized Last Names

    I haven't been here in a long time, but I wanted sto see if someone can help.

    What I want to do is very similar to a thread I saw on another forum.

    The thread is called 'Swap Last Name & First Name' and it is here Swap Last Name & First Name.

    I posted there but I'm waiting for a reply.

    I want to do the same thing - change the order of the last name and first name - but with the added difficulties that last names are captitalized and there may be 2 last names and maybe a first name and a middle name, too. I've listed some examples below:


    Original data:

    DOE John
    VAN GOGH Vincent
    DA VINCI Leonardo
    NADAL PARERA Rafael
    JIMENEZ RODRIGUEZ Miguel Ángel


    What I'd like to do is get the names in the following format:

    John Doe
    Vincent Van Gogh
    Leonardo Da Vinci
    Rafael Nadal Parera
    Miguel Ángel Jimenez Rodriguez

    I know the following function is supposed to take the original data and separate the capitalized last names into a separate cell, but I'd like to just have a continuous name in the order First Name - Midde Name - Last Name - 2nd Last Name. Thanks!


    Code:
    Sub FixAddresses() 
    
    RowNum = 1 
    Do Until Cells(RowNum, 1) = "" 
    OldText = Cells(RowNum, 1).Value 
    WordLen = Len(OldText) 
    For i = 8 To WordLen 
    If (IsNumeric(Mid(OldText, i, 1)) Or _ 
    (Mid(OldText, i, 1) = " ") Or _ 
    (Mid(OldText, i, 1) = ",") Or _ 
    (Mid(OldText, i, 1) = UCase(Mid(OldText, i, 1)))) Then 
    EndChar = i 
    Else 
    Exit For 
    End If 
    Next 
    NewText = Mid(OldText, 8, EndChar - 8) 
    Cells(RowNum, 2).Value = NewText 
    RowNum = RowNum + 1 
    Loop 
    
    End Sub
    I found that function here:

    Excel formula to extract only upper case text from a cell? - Yahoo UK & Ireland Answers

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Put this code in a standard module.

    Code:
    Option Explicit
    
    Function SWAPNAMES(InputName, Optional Delim As String = " ") As String
        
        Dim x, i As Long, n As Long
        
        If TypeName(InputName) = "Range" Then InputName = InputName.Value2
        x = Split(InputName, Delim)
        n = UBound(x)
        Select Case n
            Case Is >= 3
                For i = 2 To n
                    SWAPNAMES = SWAPNAMES & String(1, 32) & StrConv(Trim(x(i)), vbProperCase)
                Next
                SWAPNAMES = Trim(SWAPNAMES & String(1, 32) & StrConv(Trim(x(0)), vbProperCase) & String(1, 32) & StrConv(Trim(x(1)), vbProperCase))
            Case Else
                SWAPNAMES = StrConv(Trim(x(n)), vbProperCase)
                For i = 0 To n - 1
                    SWAPNAMES = SWAPNAMES & String(1, 32) & StrConv(Trim(x(i)), vbProperCase)
                Next
        End Select
        
    End Function
    and try

    =SWAPNAMES(A1)
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Data Validation With Dynamic List Of Sheet Names
    By TomyLee in forum Excel Help
    Replies: 2
    Last Post: 08-19-2013, 02:40 AM
  2. Display sheet names in a message box
    By pells in forum Excel Help
    Replies: 4
    Last Post: 02-13-2013, 07:33 PM
  3. List File Names Using Formula
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 01-20-2013, 04:04 PM
  4. List all Worksheet Names Using Formula
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 6
    Last Post: 12-17-2012, 02:47 AM
  5. Delete Names In A Specific Worksheet
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 08-14-2011, 02:38 AM

Posting Permissions

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