View Full Version : Solved: String Question
jason_kelly
03-15-2011, 06:34 AM
Hi There,
I need your help.
Let's say I have an e-mail address: firstname.lastname@domain.com
How would I go about extracting the firstname and lastname from the e-mail address:
Example:
joe.smith@domain.com
msgbox "The user's name is: Joe Smith"
Any help with this is greatly appreciated.
Cheers,
Jay
Are all the email addresses formatted in this manner?
shrivallabha
03-15-2011, 07:06 AM
You can use the following code in which I've hard coded the Range("A1") which you can make flexible:
Dim sUserName As String
Dim vUserName As Variant
sUserName = Left(Range("A1"), (InStr(Range("A1"), "@") - 1))
vUserName = Split(sUserName, ".")
MsgBox "The user's name is: " & vUserName(LBound(vUserName)) & " " & vUserName(1)
Probably, there will be far better and elegant solutions than this. Lets wait for that!
mdmackillop
03-15-2011, 08:39 AM
You could use it as a Function as in =EName(A1)
Function EName(Data)
Dim sUserName
sUserName = Split(Data, "@")(0)
sUserName = Split(sUserName, ".")
EName = "The user's name is: " & sUserName(0) & " " & sUserName(1)
End Function
jason_kelly
03-15-2011, 11:54 AM
Thanks very much to everyone for your amazing and wonderful help with this. Both methods works and I really appreciated everything.
Thanks so much for helping me out.
Cheers and have an awesome day!
Jay
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.