+ Reply to Thread
Results 1 to 34 of 34

Search a number in a sentence

  1. #1
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Search a number in a sentence

    Hello Experts, I need help please, I need a formula to search a number in a sentence. Example: In row 1, I will search a number that is greater than 50 (50 can be change anytime by the user from 1 to 300), so the answer is 150, 100, 75 & 201. The formula will be applicable from row 1 to row 5. In row 4, the answer is 135, 160 & 165. Thank you, Carlito
    Attached Files Attached Files
    Last edited by carlito.salera; 04-21-2020 at 09:36 AM.

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    You don't specify how the "valid" results are to be returned - i.e. concatenated string, one value per cell etc

    For a concatenated string, given XL version, I would say that a formula based approach will be very complex, and a User Defined Function would be a better option, e.g.:

    Please Login or Register  to view this content.
    the above, stored in a standard module in VBE, could be called from a cell as:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    where D2 holds the threshold value which, if set to 50, would return following results:

    150;100;75;201
    250;85;180;75
    140;95;200
    135;160;165
    90;210

    if, conversely, you want to return each number into separate cells post back - and advise how you want them returned, whether you want in any specific order etc...
    Last edited by XLent; 04-19-2020 at 05:26 AM. Reason: replaced strDelim with Empty

  3. #3
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello XLent, Thank you very much! The VBA work, I did additional steps to get the result I am looking for. So using the excel function will not work? Thank you, Carlito

  4. #4
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Search a number in a sentence

    Try this

    Please Login or Register  to view this content.
    Enter with Ctrl+Shift+Enter.

  5. #5
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Phuocan! Thank you very much for the help. I will try the formula. Thank you, Carlito

  6. #6
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    If, per profile, you're running 2016 I don't think you will be able to use TEXTJOIN, hence suggestion of UDF.

    If you do have access to TEXTJOIN then another, slightly shorter, alternative would be:

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

  7. #7
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Phuocam, The formula works based on the example I provided. I did a what-if by adding more nests, the formula show a different result. Do you have a formula/function that we don't to use the ctrl+shift+enter? I will use Excel 365. Thank you, Carlito

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,378

    Re: Search a number in a sentence

    If you are using Excel 365. then please update your forum profile, which currently says Excel 2016 - they are NOT the same.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  9. #9
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello XLent, Thank you very much for providing another formula. I will use your new formula to excel 365, I will get back to you. Thank you, Carlito

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,378

    Re: Search a number in a sentence

    Carlito - please don't ignore post #8. Thanks.

  11. #11
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello AliGW, Sorry, I am not ignoring your message, I am trying to change the version but failed. I click edit but not successful. Please let me know on how to change the version. Thank you, Carlito

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,378

    Re: Search a number in a sentence

    Go to Settings (top right) | Edit Profile ...

    Change the appropriate field and then Save (at the bottom).

    Sorry, but I am not able to do it for you.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  13. #13
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello AliGW, Thank you for the information, I was able to modify. The computer I am regularly using is 2016, its another computer has the 365 which I will test the latest formula I just received earlier. I will modify the status later. Thank you, Carlito

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,378

    Re: Search a number in a sentence

    OK - in that case, give both (see how I have done it under my name to the left here).

  15. #15
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello XLent, the formula worked. Thank you very much for the HELP! Carlito
    Last edited by carlito.salera; 04-23-2020 at 10:53 AM.

  16. #16
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Search a number in a sentence

    Another one
    C4
    =SUBSTITUTE(TRIM(TEXTJOIN(" ",,TEXT(RIGHT(TRIM(MID(SUBSTITUTE(B4,",",REPT(" ",200)),ROW(A$1:A$20)*200-199,200)),3),"[>300] ;[>50]0; ; ")))," ",",")

  17. #17
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Bo-Ry, Thank you for the help. I will use the formula later, I will get back to you. Thank you, Carlito

  18. #18
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Bo-Ry, Again thank you. The formula is good, it will show the number above 50, but I can't change the 50. Do you have a formula which I can change the 50 ranging from 0 to 300? Thank you, Carlito

  19. #19
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Search a number in a sentence

    Key 50 in D2

    =SUBSTITUTE(TRIM(TEXTJOIN(" ",,TEXT(RIGHT(TRIM(MID(SUBSTITUTE(B4,",",REPT(" ",200)),ROW(A$1:A$20)*200-199,200)),3),"[>300] ;[>"&$D$2&"]0; ; ")))," ",",")

  20. #20
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Bo-Ry, Again thank you. The formula is good but if "D2" is 1 then the formula will not work anymore. D2 is variable ranging from 1 to 300 but if your formula will read negative numbers then much better please. Thank you. Carlito

  21. #21
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    @Carlito, does the formula per post#6 no longer work, or are you simply trying to test / implement an alternative ?

  22. #22
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello ELent, Your formulas worked. After our chat, I closed the thread, but I received formula from another expert, and I used and commented. I did additional request also, do you have a formula that will include reading negative numbers please? Thank you

  23. #23
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    ...do you have a formula that will include reading negative numbers please?
    could you provide a file with some examples, to better illustrate your requirement?

  24. #24
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello XLent, Please see sample. In the sample, you will see the result of your 2 formulas when D2 is -10. Thank you.
    Attached Files Attached Files

  25. #25
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Search a number in a sentence

    Please try at F4

    =SUBSTITUTE(TRIM(CONCAT(TEXT(MID(SUBSTITUTE(TRIM(CONCAT(IF(ABS(CODE(MID(B4&REPT(" ",200),ROW(A$1:A$200),1))-51)<7,MID(B4&REPT(" ",200),ROW(A$1:A$200),1)," ")))," ",REPT(" ",100)),ROW(A$1:A$50)*100-99,100),"[<"&$D$2&"] ;[<300]0; ")))," ",";")
    Attached Files Attached Files

  26. #26
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    Hi Bo_Ry,

    Whilst that will work for negative value in D2, where D2 is positive you will be left with "-" in the string -- but could be handled with an outer substitute.

    I applied the same to the minor adaptation of post #6 -- changes in red.

    =SUBSTITUTE(TEXTJOIN(";",,INDEX(TEXT(TEXT(LEFT(TEXT(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B4&"@",": ",""),",","")," ","@"&REPT(" ",16)),ROW($1:$500),16),),15),"0;-0;;"),"[>"&$D$2&"]0;"""""),0)),"-;","")

    Carlito, re: UDF from post #2, modify first If

    Please Login or Register  to view this content.

  27. #27
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Search a number in a sentence

    Xlent, Thank you for point out.

    New one
    =TEXTJOIN(";",,TEXT(RIGHT(SUBSTITUTE(TRIM(MID(SUBSTITUTE(B4,",",REPT(" ",200)),ROW(A$1:A$20)*200-199,200))," "," "),4),"[>"&$D$2&"]0;"))
    Attached Files Attached Files

  28. #28
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Bo_Ry and Elent! Thank you very much for the help, highly appreciated!

  29. #29
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello XLent! My excel file I used the formula is slow and I need to hit "Enter" key twice, do you know why? Thank you

  30. #30
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    Not without more info. tbh

    What I would say is that the formula, in comparison to the UDF (post #2 + adaptation in post #26), will perform very poorly over large ranges.

    for ex. on my machine - running the formula over 10k cells takes ~30 secs, and ~0.5 sec via UDF.

  31. #31
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello XLent, I am using now the VBA and it is much better. My spreadsheet have 6000 rows and 30 columns. Do you have a formula that will read better? Thank you!

  32. #32
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Search a number in a sentence

    Bo_Ry's solution in post #27 is much faster than mine (post #26), so you should definitely try that
    note: I still think you would still need to append the outer SUBSTITUTE (per post #26) - but this will have little impact on overhead.

    regardless, for 180k cells I'd probably be erring on side of UDF, myself.

  33. #33
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Search a number in a sentence

    Another option for large Data is Power Query.

    1. assign range name to D2 => Min
    2. Create table from B3:B8

    Open Power Query/Get and Transform. Click on New Query.
    Open blank query in the editor, launch Advanced Editor and paste in the following code.

    Please Login or Register  to view this content.
    When data change, you need to press Ctrl+Alt+F5 or right click at Result and refresh to update result.
    Attached Files Attached Files

  34. #34
    Registered User
    Join Date
    04-18-2020
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Search a number in a sentence

    Hello Bo_Ry, I will try your formula. Thank you very much!

+ 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. Cross reference letter case: Beginning of sentence and middle of sentence
    By caswell1000 in forum Word Formatting & General
    Replies: 4
    Last Post: 02-07-2019, 05:25 PM
  2. [SOLVED] search button with reply sentence
    By julieta in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-17-2014, 05:24 AM
  3. VLOOKUP like function that will search text and numbers in a sentence
    By avaadore in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-06-2013, 05:59 AM
  4. Search content of *.txt file and copy certain words of a sentence to a cell
    By Joe photo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2013, 12:57 AM
  5. [SOLVED] Search for a word from a sentence....
    By raghuprasad.999 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-26-2012, 10:54 PM
  6. Replies: 2
    Last Post: 01-27-2012, 05:49 AM
  7. Search for a string in a sentence/ phrase
    By DataMcQueen917 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-09-2011, 06:06 PM

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