+ Reply to Thread
Results 1 to 12 of 12

Extracting Text from a string of text between brackets

  1. #1
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Extracting Text from a string of text between brackets

    hi there,

    Its probably best I outline an example and hoepfully you might be able to provide an answer to what I'm looking for

    There is a name in A1 ........say its John

    in A2 there are a number of names with a dollar amount in brackets to the right of each name.........for example.... Peter ($5000) Simon ($10000) John ($2000) Bob ($3000). I want to be able to look in cell A2 and find the dollar amount relating to the name in cell A1. So the result should be $2000......I have tried a combination of the following formulas

    =MID(N1,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1)

    =MID(A2,FIND(RIGHT(A1),A2)+3,(MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1)))

    but can't seem to get it......if you could please help that would be fantastic

    I use excel 2007

    Cheers

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Extracting Text from a string of text between brackets

    Like this?

    =1*MID(A2,1+FIND("$",A2,1),FIND(")",A2,1)-FIND("$",A2,1)-1)

    or

    =1*SUBSTITUTE(MID(A2,1+FIND("$",A2,1),100),")","")

    Formated as currency
    Last edited by zbor; 12-02-2009 at 10:20 AM.

  3. #3
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Extracting Text from a string of text between brackets

    thanks for that....but there is no reference to A1 in your formula

    cheers

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

    Re: Extracting Text from a string of text between brackets

    Try:

    =LOOKUP(9.999999999E+307,--("0"&MID(MID(A2,SEARCH(A1,A2),255),MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},MID(A2,SEARCH(A1,A2),255)&"0 123456789")),ROW($1:$30))))
    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.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extracting Text from a string of text between brackets

    EDIT: I'd use NBVC's... makes good point re: len assumptions - no need to waste time calculating LEN etc given the number will be of limited size anyway

    Assuming a consistent convention of name space bracket $ then:

    Please Login or Register  to view this content.
    Would be easier to split the string and work from that though, eg:

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Extracting Text from a string of text between brackets

    Sorry, didn't read carefully

    =0+MID(A2,FIND(A1,A2,1)+LEN(A1)+3,FIND(")",A2,FIND(A1,A2,1))-FIND(A1,A2,1)-LEN(A1)-3)

  7. #7
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Extracting Text from a string of text between brackets

    awesome

    =LOOKUP(9.999999999E+307,--("0"&MID(MID(A2,SEARCH(A1,A2),255),MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},MID(A2,SEARCH(A1,A2),255)&"0 123456789")),ROW($1:$30))))

    That one appears to work a treat.........I don't understand a bit of it so way ask additional questions down the track if I run into issues.....thanks again

  8. #8
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Extracting Text from a string of text between brackets

    ah ha......what happens if the name in A1 doesn't appear in A2......how can I make it come up with ""? It appears to come up with a figure when it shouldn't

  9. #9
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Extracting Text from a string of text between brackets

    zbor,

    that one doens't appear to work....it comes up with an error

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

    Re: Extracting Text from a string of text between brackets

    Quote Originally Posted by easty View Post
    ah ha......what happens if the name in A1 doesn't appear in A2......how can I make it come up with ""? It appears to come up with a figure when it shouldn't
    It should give #N/A in that case, unless you have something like Pete looking in string with Peter?

    If so, try:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Extracting Text from a string of text between brackets

    that is returning "" when the name is found in the string of text.

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

    Re: Extracting Text from a string of text between brackets

    example please.

+ 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