gisvpn
asked on
Switch around characters within a string (VBA)
Hello I have a string which always outputs
Surname, firstname
I would like to change the string to Firstname Surname using VBA. Changing around the firstname and surname and removing the ( , ) as well.
Can someone help with this ?
Thanks,
GISVPN
Surname, firstname
I would like to change the string to Firstname Surname using VBA. Changing around the firstname and surname and removing the ( , ) as well.
Can someone help with this ?
Thanks,
GISVPN
ASKER
Hi thanks for the help - I am getting an erorr on this line - im not sure why
FirstName = Right(OLDString, Val(OLDString.Length - commaPos)) ' Get First Name
Object required ?
FirstName = Right(OLDString, Val(OLDString.Length - commaPos)) ' Get First Name
Object required ?
what version of vb are you using?
ASKER
this is VBA in Word
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
perfect thanks :)
No probs, thanks for the grade.
Dim OLDString As String
Dim NewString As String
Dim commaPos As String
Dim SirName As String
Dim FirstName As String
OLDString = "Criddle, Natalie" 'Existing String
commaPos = InStr(4, OLDString, ",", 1) 'Get Comma Position
SirName = Left(OLDString, Val(commaPos - 1)) 'Get Sirname
FirstName = Right(OLDString, Val(OLDString.Length - commaPos)) ' Get First Name
NewString = FirstName & " " & SirName
MsgBox(NewString)