parse a string

  • Thread starter Thread starter Excel-General
  • Start date Start date
E

Excel-General

I think I almost have but am giving up. The fname lname string is
concatenated together with a space and I need to parse out the Lname.
Am i somewhat close?

sStr = UserForm1.g_fNameLName
Lname = Left(sStr, (InStr(1, sStr, " ")) - 1)

thanks,
 
I think I almost have but am giving up. The fname lname string is
concatenated together with a space and I need to parse out the Lname.
Am i somewhat close?

sStr = UserForm1.g_fNameLName
Lname = Left(sStr, (InStr(1, sStr, " ")) - 1)

thanks,

If there is only the one space, then:

Lname = Mid(sStr, InStr(1, sStr, " ") + 1)


--ron
 
Try this...

sStr = UserForm1.g_fNameLName
Lname = Split(sStr)(UBound(Split(sStr)))

Rick
 
This one is a little bit more efficient...

sStr = UserForm1.g_fNameLName
Lname = Mid$(sStr, InStrRev(sStr, " ") + 1)

By the way, both this solution and my previous one, will find the last
"word" (in your case, last name) in a space delimited string of text.

Rick
 
Back
Top