parse a string

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,
 
R

Ron Rosenfeld

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
 
R

Rick Rothstein \(MVP - VB\)

Try this...

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

Rick
 
R

Rick Rothstein \(MVP - VB\)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top