If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > split fullname to firstname and lastname

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-15-04, 22:42
cuongvt cuongvt is offline
Registered User
 
Join Date: May 2004
Posts: 133
split fullname to firstname and lastname

I have a column: fullname
Now I want to split the fullname column into two columns:
One is firstname ans another one is lastname.
Ex1: fullname: Vu The Cuong
-> firstname: Vu The
-> lastname: Cuong
Ex2: fullname: Nguyen Hoang Minh Chau
-> firstname: Nguyen Hoang Minh
-> lastname: Chau
Could anyone tell me the trick to solve above problem?
Please help me, I need your help.
many thanks
(I was guided about above problem in MS Access and it worked for me, could anyone tell me the trick in MS Excel also)
thank you in advanced
Code in MS access:
theLastWordInMyString = mid$(myString, instrrev(trim$(myString), " ")+1)
and
myStringWithoutLastWord = mid$(myString, 1, instrrev(trim$(myString), " ")-1)
Reply With Quote
  #2 (permalink)  
Old 12-16-04, 04:07
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Since there is no easy way to search backwords in excel (at least that i know of id set a UDF to do this

i.e.
Code:
Function Lastword(ByVal rng As Range, ByVal bolTest As Boolean) As String
    
    
    Select Case bolTest
        Case True
            Lastword = Mid$(rng.Value, InStrRev(Trim$(rng.Value), " ") + 1)
        Case False
            Lastword = Mid$(rng.Value, 1, InStrRev(Trim$(rng.Value), " ") - 1)
    End Select
End Function
hth
Dave
Reply With Quote
  #3 (permalink)  
Old 12-16-04, 05:41
cuongvt cuongvt is offline
Registered User
 
Join Date: May 2004
Posts: 133
Thank for help
I'm not know much about VBA in Excel. Could you tell me where I must put above function so that it take effect.
thank you
Reply With Quote
  #4 (permalink)  
Old 12-16-04, 06:00
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Ok, If you get into the VBE(Press Alt+F11)
Go to Insert then Choose Module
Paste the code there,
Now to work with this on your Worksheet go back to excel, Choose the correct cell and Type

=LastWord(A1,True)
(assuming A1 is the cell you want to use)
True Indicates the last word
Replace this with false for everything else

Dave
Reply With Quote
  #5 (permalink)  
Old 12-16-04, 20:55
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
You can also do this with Excel formulas:

See Chip Pearson's Site
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
  #6 (permalink)  
Old 12-17-04, 03:26
cuongvt cuongvt is offline
Registered User
 
Join Date: May 2004
Posts: 133
thank you.
All you helped me so much.
thank again
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On