+ Reply to Thread
Results 1 to 4 of 4

Manipulating strings (finding the substring between two spaces)

  1. #1
    Registered User
    Join Date
    12-19-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    24

    Manipulating strings (finding the substring between two spaces)

    Hi guys,

    I was unsure where to post this as this is maybe easier solved with a combination of formulas but anyway, here goes. I have a couple of strings like this in my worksheet:

    AB 179 EFGH
    AB 42 EFGH
    AB 44798 EFGH
    ...and so forth

    I'd very much like to pull the substring that is between the two spaces (i.e. 179, 42 and 44798 respectively). I've done a whole lot of experimenting and usually end up (very mad) with something like "AB 179" or "EFGH". In addition, I'm having trouble getting it to work for all different lengths of the substring (i.e. 3, 2, 5 and n...)

    Any help on this matter would be greatly appreciated.

    Many thanks and godspeed!

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Manipulating strings (finding the substring between two spaces)


    Hi,

    just use Split function, see in VBA inner help …

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Manipulating strings (finding the substring between two spaces)

    If those strings are in column A, starting with A1, then you can use this formula (e.g. in B1):

    =MID(A1,FIND(" ",A1)+1,FIND(" ",A1,FIND(" ",A1)+1)-FIND(" ",A1))

    then copy down. Note that these will still be strings - if you want to convert them to actual numbers, just add +0 to the end of the formula.

    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    12-19-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Manipulating strings (finding the substring between two spaces)

    Quote Originally Posted by Marc L View Post

    Hi,

    just use Split function, see in VBA inner help …
    Wow! That was almost too easy. I ended up with something like this:
    Please Login or Register  to view this content.
    Adding the (1) at the end was a simple way of returning only the second fragment of the string!
    Quote Originally Posted by Pete_UK View Post
    If those strings are in column A, starting with A1, then you can use this formula (e.g. in B1):

    =MID(A1,FIND(" ",A1)+1,FIND(" ",A1,FIND(" ",A1)+1)-FIND(" ",A1))

    then copy down. Note that these will still be strings - if you want to convert them to actual numbers, just add +0 to the end of the formula.

    Hope this helps.

    Pete
    Much obliged! I am sure this will prove helpful down the line...I was quite unaware of the =FIND-function.

    Thanks to both of you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 07-04-2012, 08:16 AM
  2. Substring searching - excluding similar strings
    By FayePearson in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-25-2012, 08:15 PM
  3. Manipulating strings
    By therealjag in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2010, 08:32 AM
  4. Manipulating Strings
    By OlYeller21 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-06-2009, 02:08 PM
  5. Manipulating Strings
    By Leslie Coover in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2005, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1