Extracting right-hand word from text

No Waiting

New Member
Joined
Jan 26, 2005
Messages
5
I have a simply problem, but am having trouble finding the solution!

I have a column like this -

Mr & Mrs John Brown
Jane Smith
Mr Tom Gray
Peter Hancock
Miss Jill Bradley-Smith

and need to split it into two columns, thus

Mr & Mrs John
Jane
Mr Tom
Peter
Miss Jill

and

Brown
Smith
Gray
Hancock
Bradley-Smith

All help very gratefully received!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi,

the code will split ;
Title in Col.C
First Name in Co.D and
Last Name in Col.E

Code:
Sub split_name()
Dim i As Integer, a(7) As String, b() As String
Dim x As Integer, y As String, r As Range
a(0) = "MR."
a(1) = "MR "
a(2) = "MRS."
a(3) = "MRS "
a(4) = "MISS "
a(5) = "MS."
a(6) = "MS "
a(7) = "& "
Application.ScreenUpdating = False
With ActiveSheet
    .Columns("c:e").Clear
For Each r In .Range("a1", .Range("a65536").End(xlUp))
    For i = LBound(a) To UBound(a)
        If InStr(UCase(r), a(i)) > 0 Then
            x = x + 1
        End If
    Next
    b = Split(r)
    If x = 0 Then
            For i = LBound(b) To UBound(b)
                .Cells(r.Row, i + 4) = b(i)
            Next
        Else
            For i = 0 To x - 1
                y = y & b(i) & " "
            Next
            .Cells(r.Row, 3) = Left(y, Len(y) - 1)
            ii = 5
            For i = x To UBound(b)
                .Cells(r.Row, i + 4 - x) = b(i)
            Next
    End If
    x = 0
    y = ""
    Erase b
Next
End With
Erase a
Application.ScreenUpdating = True
End Sub
if you want to add more items to the title array like DR PROF etc
simply increase number of a(7) in the Dim statement like a(11) and add
a(8)="DR."
a(9)="DR "
a(10)="PROF."
a(11)="PROF "

rgds,
jindon
 
Upvote 0

Forum statistics

Threads
1,222,383
Messages
6,165,660
Members
451,983
Latest member
Raph24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top