Link to home
Start Free TrialLog in
Avatar of BauwensER
BauwensERFlag for Belgium

asked on

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

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!!
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want this ina query then...

Left(yourfield , instr(yourfield & " ", " ")-1)
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