Solved

Find the first space in a string and only return the characters before that space using vba

Posted on 2012-03-15
3
381 Views
Last Modified: 2012-03-16
Is there an easy way to find in a string and only return the characters before the first space in the string.

For example: married  divorce single blabla

should return married in this example

many thanks!!
0
Comment
Question by:BauwensER
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 37725041
Try this:


Dim strYourString as string
strYourString = "married divorced etc"

msgbox Split(strYourString," ") (0)
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37725116
If you want this ina query then...

Left(yourfield , instr(yourfield & " ", " ")-1)
0
 

Expert Comment

by:baglass
ID: 37725133
The following will break up the source string [the first argument to Split()] using the second argument as the delimiter.  
The delimter may be more than one character in length.  
If the source string is empy then the size of the array will be -1.
If the delimter is not found then the whole string is returned in element 0 of the array.
'---------------------------------------------------------------------------
Dim mystring() As String

Sub testme()

   mystring = Split("this is a sample string", " ")
   if ubound(mystring) >= 0 then
      Debug.Print mystring(0)
   endif

End Sub
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

760 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

22 Experts available now in Live!

Get 1:1 Help Now