PDA

View Full Version : Sub string help



majaro
06-15-2009, 10:47 AM
Have a column that I need to get the part of the string before the @ in an email address. For example majaro@vbaexpress.com should yield just majaro. The part before the @ sign can be any length. Can someone show me how to do that with just a string sub string function? Thanks

CreganTur
06-15-2009, 11:11 AM
You can use the InStr() function to get the location of the @ within the string, and then use that along with the Right() function to pull out just what you want. Like this:
Right(anyone@mailserver.com, Len("anyone@mailserver.com") - InStr(1,"anyone@mailserver.com","@",vbTextCompare))
This will yield a result of: mailserver.com

HTH:thumb

majaro
06-15-2009, 11:56 AM
Hmmm..I just want the result to be "anyone" not mailserver.com

CreganTur
06-15-2009, 12:04 PM
Hmmm..I just want the result to be "anyone" not mailserver.com

Sorry, misread your post.

Then use the Left() Function and subtract the value returned by the InStr() Function by one.

Play around with it and see if you can get it to work. If not, someone will be happy to help.

Bob Phillips
06-15-2009, 02:12 PM
In a formula

=LEFT(A1,FIND("@",A1)-1)

p45cal
06-15-2009, 03:56 PM
in vba:FirstBit=split("majaro@vbaexpress.com","@")(0)