+ Reply to Thread
Results 1 to 12 of 12

Performing numeric comparison after matching a string of text

  1. #1
    Registered User
    Join Date
    07-21-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007/2010
    Posts
    11

    Performing numeric comparison after matching a string of text

    Hi everyone,

    I appreciate your help in advance!

    I have a string block similar to what is seen below that I export out of a tool (that I cannot edit) -- it looks similar to this:

    Matches:

    Food,Pizza=Cheese,Topping=Mushroom,Extras=Soda(12),Breadsticks=TooFat
    Sports,Baseball=Fun,Basketball=Soso,Soccer=Footy(1500),Badminton=lolseriously


    I am trying to write a formula (preferably) or use a VB module to read a string of text and perform a numeric comparison to the portion in paranthesis. So far I have this - which is probably entirely wrong .



    Code:
    Please Login or Register  to view this content.
    In the example above, I am trying to do the following -- search for the string "Topping=Mushroom,Extras=Soda(" and then perform a numeric comparison of the following number (12 in the example above). I basically want to match the string and then identify if the number is less than 12.

    I would prefer the formula to return the actual finding -- examples being: Extras=Soda(8), Extras=Soda(4), etc., but true/false is also acceptable!



    Thank you so very much in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: Performing numeric comparison after matching a string of text

    Try this;
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    That should return the string you want, the original strings are in a similar format. Does this answer all your questions?
    Sincerely
    S?ren Larsen

    "Give a man a fish, and you'll feed him for a day. Give a man a fishing rod, and he'll steal your yacht!"

  3. #3
    Forum Contributor BenMiller's Avatar
    Join Date
    12-06-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    254

    Re: Performing numeric comparison after matching a string of text

    This will return the actual numerical value.
    =--MID(A1,FIND("Topping=Mushroom,Extras=Soda(",A1)+29,FIND(")",A1)-(FIND("Topping=Mushroom,Extras=Soda(",A1)+29))

  4. #4
    Registered User
    Join Date
    07-21-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007/2010
    Posts
    11

    Re: Performing numeric comparison after matching a string of text

    Thanks for the very quick response!!

    There are a couple of things at play here which make the above solutions not quite sufficent .


    First, the actual ouput of the tool looks similar to the sample below. As you can see, the text that will be examined is *not fixed length* -- furthermore the numeric could be 3 or 4 characters in length (i.e., 500, 1000, 8000).

    Second, I actually need to *compare* the number (only) after the matching string is found:

    Process:

    a) detect the string Topping=Mushroom,Extras=Soda
    b) compare the next characters using a less than symbol (i.e.: (500) or (1000) or (8000)
    c) report back findings of one (or more -- doesnt matter) hits - preferably in the format of: Extras=Soda(526), Extras=Soda(8234), etc. but True/False is fine too!


    I hope this makes sense, and please let me know if you need more clarification.


    Please Login or Register  to view this content.
    Last edited by kwondra34; 07-19-2012 at 07:32 PM.

  5. #5
    Forum Contributor BenMiller's Avatar
    Join Date
    12-06-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    254

    Re: Performing numeric comparison after matching a string of text

    Maybe I'm not understanding ... will the text "Topping=Mushroom,Extras=Soda" appear more than once in each string (cell)?

    Also, it is safe to say that the number you're looking for is always between the first two parentheses in the string?

  6. #6
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: Performing numeric comparison after matching a string of text

    This should give you the number irregardless of length:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    But perhaps you need to share a sample worksheet.

  7. #7
    Registered User
    Join Date
    07-21-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007/2010
    Posts
    11

    Re: Performing numeric comparison after matching a string of text

    Maybe I'm not understanding ... will the text "Topping=Mushroom,Extras=Soda" appear more than once in each string (cell)?
    Yes -- it appears multiple times in a single cell.

    Also, it is safe to say that the number you're looking for is always between the first two parentheses in the string?
    Yes, it will always appear between the first two parenthesis.


    Soren, thank you very much - I see now I can append '> 1000' to the end of the formula you provided to perform the math.

    I have to apologize for not showing the true-true layout of what is exported -- it is as follows -- new additions in underline. As you can see, this: All Findings (>= 8000 total structures) is causing the formula to return #VALUE! When it is removed, it works PERFECTLY!! We are very close -- thanks so much!

    And again, there are MULTIPLE occurences in each cell -- I somehow need to pull the HIGHEST number out and use that to compare with 1000. Can this be done?


    Furthermore, the string must be matched first because only occurences of 'Topping=Mushroom,Extras=Soda' should be found. If 'Topping=MoreCheese,Extras=Soda' was detected, the finding should *not* be evaluated.


    Summary:

    Enemeration of Food and Sports

    Details:

    This tool exports the desired attributes you selected.


    Suggestion:

    n/a

    Matches:

    All Findings (>= 8000 total structures)

    Food,Pizza=Cheese,Topping=Mushroom,Extras=Soda(12),Breadsticks=TooFat
    Sports,Baseball=Fun,Basketball=Soso,Soccer=Footy(1500),Badminton=lolseriously

    Legend :

    {Activity}
    Pizza={pza}
    Topping={tp}
    Extras={ext}
    Breadsticks={brs}
    {understood_questionmark}
    Last edited by kwondra34; 07-19-2012 at 08:02 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: Performing numeric comparison after matching a string of text

    Something like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-21-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007/2010
    Posts
    11

    Re: Performing numeric comparison after matching a string of text

    Yes I figured that out -- see the above post for my unspoken delimma! Thanks!

  10. #10
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: Performing numeric comparison after matching a string of text

    (>= 8000 total structures)
    You could write a crazy long formula to convert the above to an =IF() statement, but, as mentioned, it'll be crazy long! What you can do, if the logic is always ">=", is to use a similar approach as in post #8 to grab the number; 8000 in this case, and then connect the stuff in an =IF() statement. Otherwise you need vba which is not my strong suit.

    If you find that you need vba, then I suggest that you mark this thread as solved, and start a new one which is dedicated to that issue.

  11. #11
    Registered User
    Join Date
    07-21-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007/2010
    Posts
    11

    Re: Performing numeric comparison after matching a string of text

    Thanks for your continued support Soren.

    This part is true - yes:

    the logic is always "(>=8000 total structures)"


    The problem is that it is a hinderance that I cannot remove per how it is exported. It is just a hinderance -- that number is irrelevant to what I actually need to pull out. I need to pull out the bold portions below:

    Food,Pizza=Cheese,Topping=Mushroom,Extras=Soda(12),Breadsticks=TooFat
    Sports,Baseball=Fun,Basketball=Soso,Soccer=Footy(1500),Badminton=lolseriously



    This line - because it contains ( <a number> ) seems to be causing the formula to choke:

    All Findings (>= 8000 total structures)

  12. #12
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: Performing numeric comparison after matching a string of text

    I'm pretty confused at this point... I think you'll need to upload a sample workbook also containing your desired results.

  13. #13
    Registered User
    Join Date
    07-21-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007/2010
    Posts
    11

    Re: Performing numeric comparison after matching a string of text

    Thanks Soren. I will try to get you a sample spreadsheet shortly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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