View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Replace "FIRSTNAME LASTNAME" with "LAST"

Custom format
000000-2

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"chrishutson123" wrote in message
...
Thank you so much!!! That worked like a champ. I have another question:

I have a cell with account numbers formatted like "1234-2" or "12345-2" or
"123456-2". The main part of the account number could be as few as 3
characters and as many as 6 characters followed by a "-2". I need to
convert
this field to a 40 character string with leading zeroes. Can you help?

"Gary''s Student" wrote:

Without VBA:

In B1, enter:
=SEARCH("|",SUBSTITUTE(A1," ","|",(LEN(A1)-LEN(SUBSTITUTE(A1,"
","")))))+1


In C1, enter:
=MID(A1,B1,4)

With VBA:

Sub lastname()
s = Split(ActiveCell.Value, " ")
u = UBound(s)
MsgBox (Left(s(u), 4))
End Sub

--
Gary''s Student - gsnu200775


"chrishutson123" wrote:

Hello:

I have a cell with the string "FIRSTNAME LASTNAME". I would like to
replace
it with "LAST". I have some special cases:

"MERRILL C CURRIER" should yield "CURR"
"JON SUN" should yield "SUN "
"JON C SUN" should yield "SUN "
"TRAVIS SMITH" should yield "SMIT"

Can anyone help? I am very appreciative. You should know that I am
new to
VBA in Excel. Thanks.

Chris.