swapping data round in excel

PhilipLawrence99

New Member
Joined
Aug 11, 2002
Messages
20
Hi there, Football related question this time.... I have a list of all the players in the preier league that I need to import into a program to monitor the league for 2002-2003 but the list needs to be in a certain format. My list is set out as follows:
ColumnA = Player No.
ColumnB = Player Name (Forename Surname)
ColumnC = Position

What I need to do is transpose the forename and surname in columnB so it reads Surname,Forename with a comma separating the surname and forename but still in the same cell.

any thoughts on how to do this as there's over 500 to type in manually otherwise....

If you want the program to use then go to http://www.ngthomas.co.uk/index.html

Look forward to hearing from you guys soon.

cheers
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
The following macro should do the trick:-

Option Explicit

Sub Name_Order()
Dim rng As Range
Dim cell As Object

Set rng = Range("C2:C4")

For Each cell In rng
If Not (IsEmpty(cell) Or (cell = "") Or (IsNull(cell))) Then
Dim myArray() As String
myArray() = Split(cell, " ")
cell.Value = myArray(1) & ", " & myArray(0)
End If
Next cell

End Sub

This is based on a firstame and lastname and does not cater for multiple names
 
Upvote 0
That's great, thank you for that but there's loads of double barrelled surnames in the league and I'll need to cater for those as well. any thoughts???

Cheers,
 
Upvote 0
When you say double barrelled - are these hyphenated or seperate words as in alf inge halaand, or whatever his name is?

The code could be amended such that alf inge halaand would become halaand, alf inge and firstname sur-name would become surname, firstname.

Tom.
 
Upvote 0
Try,

Option Explicit

Sub Name_Order()

Dim x As Integer
Dim rng As Range
Dim cell As Object
Dim newname As String

Set rng = Range("C1:C10")

For Each cell In rng
If Not (IsEmpty(cell) Or (cell = "") Or (IsNull(cell))) Then
Dim myArray() As String
myArray() = Split(cell, " ")
newname = myArray(UBound(myArray)) & ", "
For x = 0 To (UBound(myArray) - 1)
newname = newname & " " & myArray(x)
Next x
cell.Value = newname
End If
Next cell

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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