?
Solved

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

Posted on 2012-03-15
3
Medium Priority
?
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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