+ Reply to Thread
Results 1 to 11 of 11

Mid function

  1. #1
    Forum Contributor
    Join Date
    05-13-2005
    Posts
    118

    Mid function

    is there some variant of the Mid function that returns a characters to the left of the starting position intead of to the right?

    I know I can find the starting point of a sub-string then strip off that sub-string and everything to the right of it, then simply use the Right function to obtain what I'm looking for, but I thought a Mid function that runs to the left would be easier.

    Thanks,

    Gary Willick

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Mid function

    nygwnj,

    Can we have an example of the string, and what the function should return?
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Contributor
    Join Date
    05-13-2005
    Posts
    118

    Re: Mid function

    I just realized I can use the Left function up until the spot I found my sub-string - 1 (to allow for a space), then use the right function to obtain my desired sub-string.

    The string would look like:

    Willick 07646 batch 4678

    So I could find the position of the 'b' in batch, subract 1, use the Left function to that position to obtain:
    Willick 07646
    then
    use right to obtain the zip code, 07646.

    but I'm still interested in a leftward proceeding Mid function.

  4. #4
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Mid function

    I bet there are a dozen or so ways to get the results you're looking for, but I have never seen a simple native VB function that would take the characters to the left...I'll keep watching this post in case someone comes up with the answer. I'm curious and hopeful
    -Greg If this is helpful, pls click Star icon in lower left corner

  5. #5
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Mexico
    Posts
    200

    Re: Mid function

    Try this:
    =MID(A2,FIND("b",A2)-6,5)

  6. #6
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Mid function

    nygwnj,

    If this is in cell A1:
    Willick 07646 batch 4678

    In B1 copy this formula:
    =MID(A1,FIND(" ",A1,1)+1,FIND(" batch",A1,1)-1-FIND(" ",A1,1))

    B1 will display:
    07646

  7. #7
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Mid function

    @Armando:
    Try this:
    =MID(A2,FIND("b",A2)-6,5)
    I like it

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Mid function

    If you are looking for the second substring (or "word") try:

    =TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),100,100))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  9. #9
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Mid function

    NBVC,

    Nice....

    If we were looking for the third substring, what would your formula look like?

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Mid function

    Like so:

    =TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),200,100))

  11. #11
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Mid function

    NBVC,

    Thank you again.

    Now I understand how the formula works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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