Solved

Seperate Strings into words

Posted on 2000-05-14
6
177 Views
Last Modified: 2010-05-02
Hi

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

Regards
admoller
0
Comment
Question by:admoller
6 Comments
 
LVL 1

Expert Comment

by:ofirg
Comment Utility
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
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
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
 
LVL 6

Accepted Solution

by:
Marine earned 50 total points
Comment Utility
'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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 

Author Comment

by:admoller
Comment Utility
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
 
LVL 6

Expert Comment

by:Marine
Comment Utility
Your Welcome.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now