Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
aph aph is offline
external usenet poster
 
Posts: 1
Default Find last word in cell


Hi,

How can I find the last word in a cell containing "Firstname Initial
Lastname"? I have tried the Mid and Left functions with a for next loop
but I think I need to work backwards to find the space.

Any suggestiongs please.

Andrew


--
aph
------------------------------------------------------------------------
aph's Profile: http://www.excelforum.com/member.php...o&userid=17175
View this thread: http://www.excelforum.com/showthread...hreadid=476748

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Find last word in cell

aph wrote:

Hi,

How can I find the last word in a cell containing "Firstname
InitialLastname"? I have tried the Mid and Left functions with a for next
loopbut I think I need to work backwards to find the space.

Any suggestiongs please.


Use the Mid & Left functions to separate the firstname from the
remainder, then do it again on the remainder to separate the initial
from the lastname.


--
Gordon Rainsford
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find last word in cell

This UDF returns the lastname (use space as Separchar):

Function Lastword(InputString As String, SeparChar As String) As String
Dim i As Long
Dim ByteStr, ResultStr As String
ResultStr = ""
For i = Len(InputString) To 1 Step -1
ByteStr = Mid(InputString, i, 1)
If ByteStr = SeparChar Then
ResultStr = Right(InputString, Len(InputString) - i)
Exit For
End If
Next i
Lastword = ResultStr
End Function

Regards,
Stefi


"Gordon Rainsford" wrote:

aph wrote:

Hi,

How can I find the last word in a cell containing "Firstname
InitialLastname"? I have tried the Mid and Left functions with a for next
loopbut I think I need to work backwards to find the space.

Any suggestiongs please.


Use the Mid & Left functions to separate the firstname from the
remainder, then do it again on the remainder to separate the initial
from the lastname.


--
Gordon Rainsford

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Find last word in cell

Public Function FindName(ByVal MyName As String)

FindName = Right(MyName, Len(MyName) - InStrRev(MyName, " "))

End Function

Example of use:
MyName = "Kenneth Graham Dales"
LastName = FindName(MyName)
? LastName
Dales
MyName = Trim(Replace(MyName, LastName, ""))
? MyName
Kenneth Graham
MiddleName = FindName(MyName)
? MiddleName
Graham
FirstName = Trim(Replace(MyName, MiddleName, ""))
? FirstName
Kenneth

--
- K Dales


"aph" wrote:


Hi,

How can I find the last word in a cell containing "Firstname Initial
Lastname"? I have tried the Mid and Left functions with a for next loop
but I think I need to work backwards to find the space.

Any suggestiongs please.

Andrew


--
aph
------------------------------------------------------------------------
aph's Profile: http://www.excelforum.com/member.php...o&userid=17175
View this thread: http://www.excelforum.com/showthread...hreadid=476748


  #5   Report Post  
Posted to microsoft.public.excel.programming
aph aph is offline
external usenet poster
 
Posts: 1
Default Find last word in cell


Kenneth

Works perfectly - thanks (I am sure the others do as well but I do like
a 1 line !)

Andrew


K Dales Wrote:
Public Function FindName(ByVal MyName As String)

FindName = Right(MyName, Len(MyName) - InStrRev(MyName, " "))

End Function

Example of use:
MyName = "Kenneth Graham Dales"
LastName = FindName(MyName)
? LastName
Dales
MyName = Trim(Replace(MyName, LastName, ""))
? MyName
Kenneth Graham
MiddleName = FindName(MyName)
? MiddleName
Graham
FirstName = Trim(Replace(MyName, MiddleName, ""))
? FirstName
Kenneth

--
- K Dales


"aph" wrote:


Hi,

How can I find the last word in a cell containing "Firstname Initial
Lastname"? I have tried the Mid and Left functions with a for next

loop
but I think I need to work backwards to find the space.

Any suggestiongs please.

Andrew


--
aph

------------------------------------------------------------------------
aph's Profile:

http://www.excelforum.com/member.php...o&userid=17175
View this thread:

http://www.excelforum.com/showthread...hreadid=476748




--
aph
------------------------------------------------------------------------
aph's Profile: http://www.excelforum.com/member.php...o&userid=17175
View this thread: http://www.excelforum.com/showthread...hreadid=476748



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find last word in cell

Try the SPLIT() function. It is similar to Text to Columns in the worksheet.
--
Gary''s Student


"aph" wrote:


Hi,

How can I find the last word in a cell containing "Firstname Initial
Lastname"? I have tried the Mid and Left functions with a for next loop
but I think I need to work backwards to find the space.

Any suggestiongs please.

Andrew


--
aph
------------------------------------------------------------------------
aph's Profile: http://www.excelforum.com/member.php...o&userid=17175
View this thread: http://www.excelforum.com/showthread...hreadid=476748


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a cell's content in another cell but only as whole word(s) Paul Excel Worksheet Functions 2 February 5th 09 09:41 AM
In Excel, how do I find one word in a set of text in a cell? man818 Excel Discussion (Misc queries) 4 May 20th 06 02:20 PM
Find part of a word in cell Elaine Excel Discussion (Misc queries) 7 March 3rd 06 07:37 PM
find word in a cell then change cell format [email protected] Excel Programming 2 May 23rd 05 01:21 PM
Find a certain word in excel and select the cell desmondleow[_8_] Excel Programming 3 December 18th 03 02:39 PM


All times are GMT +1. The time now is 02:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"