Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Seperate Strings into words

Hi

How do you seperate a string, e.g. a Surname from a Christian Name with VBA.

Regards
admoller
0
admoller
Asked:
admoller
1 Solution
 
ofirgCommented:
It's hard for me to understand what is it you want to do, but the best way to seperate a string to word is by the "split" function

Joy and Happiness
0
 
bruintjeCommented:
that depends on how the string is formed

example

declare a few public variables in the module

Dim m_strSurName As String
Dim m_strCristianName As String

then take this function

function SplitNames(Byval Name As String) As Boolean

Dim strCompleteName As String
Dim lngSeper As Long

strName = "Hakkebar, Bertje"

'get the position of the seperator
lngSeper = InStr(1, ",", strName)

m_strSurName = Left(strName, Len(strName) - lngSeper + 1)

m_strChristianName = Right(strName, Len(strName) - lngSeper + 1)

end function


something like this, of course it still depends on the format of your names, but the idea is clear ....

can be errorprone, no testing done :O)

HTH:O)Bruintje
0
 
MarineCommented:
'Say this is input
'"Hakkebar, Bertje"
strName = "Hakkebar, Bertje"
sArray = Split(strName,",")

msgbox sArray(0) & "  " & sArray(1)

you can loop now ofcourse from lBound to Ubound of sArray since when you use Split Function it creates an array of values for you. In this example teh delimter that is used is a comma.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AzraSoundCommented:
let it be noted that the split function is only available in vb6 but the Instr function works just as well here as bruintje points out
0
 
admollerAuthor Commented:
Thanks Marine
I had noticed before the split function mentioned - but there was little help in the help on it. Your example is bang-on.
regards
admoller
0
 
MarineCommented:
Your Welcome.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now