Solved

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

Posted on 2012-03-15
3
388 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

728 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