Looking for formula to search for particular pattern in Excel











up vote
-1
down vote

favorite












I am looking for formula to search for "words" with a particular letter pattern, like INNSA1 or INMAA4 or INPTPB, where the word starts with IN and ends with 4, 1, 6, or B. The words are always exactly six characters and the letters can be either upper- or lower-case.



A collection of Excel cells each contain a sentence in which one or more such words will be found (always at least one). For example:




  • My Custom location is INNSA1

  • I work at INMAA4

  • I want to go to INDEL6

  • INNSAB IS BOARDER LOCATION


The word (or words, if more than one), may be in any position in the sentence. The target words will always be separate words, not part of a larger word.



For each sentence (i.e., cell), I want to search for the presence of any word fitting the described letter pattern, and return this word as a value.










share|improve this question









New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    Heavy vote-down for shouting in all-capitals. Strongly suggest you edit.
    – Michael Harvey
    Nov 17 at 9:32










  • I don't really have a clear picture of your requirement. Are you looking for the presence (true/false) of a "word" (i.e., character string containing only alphanumerics--letters/numbers but no spaces or other kinds of characters), matching a pattern (starts with IN, and ends with 4, 1, 6, or b), which can be located anywhere in a "sentence" but delimited from it by space or punctuation, that is contained in a single cell? Is it always a separate "word" or can it be a character string embedded in a longer "word"? (cont'd)
    – fixer1234
    Nov 18 at 2:21










  • Is it always exactly 6 characters? Are the letters always uppercase? What do the "sentences" look like? Can the "word" appear more than once, including as part of a larger word? This would be easier to understand if you include examples of the sentences that represent the range of conditions.
    – fixer1234
    Nov 18 at 2:21










  • Also, as Gary's Student interpreted, is the word the only thing in the cell or is it somewhere within other text in a cell (which are very different requirements)?
    – fixer1234
    Nov 18 at 2:32










  • I want to search particular pattern in a sentence in a cell. e.g. " My Custom location is INNSA1" OR "I work at INMAA4" or "I want to go to INDEL6"
    – ajit maurya
    Nov 18 at 17:06

















up vote
-1
down vote

favorite












I am looking for formula to search for "words" with a particular letter pattern, like INNSA1 or INMAA4 or INPTPB, where the word starts with IN and ends with 4, 1, 6, or B. The words are always exactly six characters and the letters can be either upper- or lower-case.



A collection of Excel cells each contain a sentence in which one or more such words will be found (always at least one). For example:




  • My Custom location is INNSA1

  • I work at INMAA4

  • I want to go to INDEL6

  • INNSAB IS BOARDER LOCATION


The word (or words, if more than one), may be in any position in the sentence. The target words will always be separate words, not part of a larger word.



For each sentence (i.e., cell), I want to search for the presence of any word fitting the described letter pattern, and return this word as a value.










share|improve this question









New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    Heavy vote-down for shouting in all-capitals. Strongly suggest you edit.
    – Michael Harvey
    Nov 17 at 9:32










  • I don't really have a clear picture of your requirement. Are you looking for the presence (true/false) of a "word" (i.e., character string containing only alphanumerics--letters/numbers but no spaces or other kinds of characters), matching a pattern (starts with IN, and ends with 4, 1, 6, or b), which can be located anywhere in a "sentence" but delimited from it by space or punctuation, that is contained in a single cell? Is it always a separate "word" or can it be a character string embedded in a longer "word"? (cont'd)
    – fixer1234
    Nov 18 at 2:21










  • Is it always exactly 6 characters? Are the letters always uppercase? What do the "sentences" look like? Can the "word" appear more than once, including as part of a larger word? This would be easier to understand if you include examples of the sentences that represent the range of conditions.
    – fixer1234
    Nov 18 at 2:21










  • Also, as Gary's Student interpreted, is the word the only thing in the cell or is it somewhere within other text in a cell (which are very different requirements)?
    – fixer1234
    Nov 18 at 2:32










  • I want to search particular pattern in a sentence in a cell. e.g. " My Custom location is INNSA1" OR "I work at INMAA4" or "I want to go to INDEL6"
    – ajit maurya
    Nov 18 at 17:06















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am looking for formula to search for "words" with a particular letter pattern, like INNSA1 or INMAA4 or INPTPB, where the word starts with IN and ends with 4, 1, 6, or B. The words are always exactly six characters and the letters can be either upper- or lower-case.



A collection of Excel cells each contain a sentence in which one or more such words will be found (always at least one). For example:




  • My Custom location is INNSA1

  • I work at INMAA4

  • I want to go to INDEL6

  • INNSAB IS BOARDER LOCATION


The word (or words, if more than one), may be in any position in the sentence. The target words will always be separate words, not part of a larger word.



For each sentence (i.e., cell), I want to search for the presence of any word fitting the described letter pattern, and return this word as a value.










share|improve this question









New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am looking for formula to search for "words" with a particular letter pattern, like INNSA1 or INMAA4 or INPTPB, where the word starts with IN and ends with 4, 1, 6, or B. The words are always exactly six characters and the letters can be either upper- or lower-case.



A collection of Excel cells each contain a sentence in which one or more such words will be found (always at least one). For example:




  • My Custom location is INNSA1

  • I work at INMAA4

  • I want to go to INDEL6

  • INNSAB IS BOARDER LOCATION


The word (or words, if more than one), may be in any position in the sentence. The target words will always be separate words, not part of a larger word.



For each sentence (i.e., cell), I want to search for the presence of any word fitting the described letter pattern, and return this word as a value.







microsoft-excel worksheet-function microsoft-excel-2010 microsoft-excel-2013






share|improve this question









New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 20 at 7:25









fixer1234

17.3k144280




17.3k144280






New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 9:22









ajit maurya

112




112




New contributor




ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ajit maurya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    Heavy vote-down for shouting in all-capitals. Strongly suggest you edit.
    – Michael Harvey
    Nov 17 at 9:32










  • I don't really have a clear picture of your requirement. Are you looking for the presence (true/false) of a "word" (i.e., character string containing only alphanumerics--letters/numbers but no spaces or other kinds of characters), matching a pattern (starts with IN, and ends with 4, 1, 6, or b), which can be located anywhere in a "sentence" but delimited from it by space or punctuation, that is contained in a single cell? Is it always a separate "word" or can it be a character string embedded in a longer "word"? (cont'd)
    – fixer1234
    Nov 18 at 2:21










  • Is it always exactly 6 characters? Are the letters always uppercase? What do the "sentences" look like? Can the "word" appear more than once, including as part of a larger word? This would be easier to understand if you include examples of the sentences that represent the range of conditions.
    – fixer1234
    Nov 18 at 2:21










  • Also, as Gary's Student interpreted, is the word the only thing in the cell or is it somewhere within other text in a cell (which are very different requirements)?
    – fixer1234
    Nov 18 at 2:32










  • I want to search particular pattern in a sentence in a cell. e.g. " My Custom location is INNSA1" OR "I work at INMAA4" or "I want to go to INDEL6"
    – ajit maurya
    Nov 18 at 17:06
















  • 2




    Heavy vote-down for shouting in all-capitals. Strongly suggest you edit.
    – Michael Harvey
    Nov 17 at 9:32










  • I don't really have a clear picture of your requirement. Are you looking for the presence (true/false) of a "word" (i.e., character string containing only alphanumerics--letters/numbers but no spaces or other kinds of characters), matching a pattern (starts with IN, and ends with 4, 1, 6, or b), which can be located anywhere in a "sentence" but delimited from it by space or punctuation, that is contained in a single cell? Is it always a separate "word" or can it be a character string embedded in a longer "word"? (cont'd)
    – fixer1234
    Nov 18 at 2:21










  • Is it always exactly 6 characters? Are the letters always uppercase? What do the "sentences" look like? Can the "word" appear more than once, including as part of a larger word? This would be easier to understand if you include examples of the sentences that represent the range of conditions.
    – fixer1234
    Nov 18 at 2:21










  • Also, as Gary's Student interpreted, is the word the only thing in the cell or is it somewhere within other text in a cell (which are very different requirements)?
    – fixer1234
    Nov 18 at 2:32










  • I want to search particular pattern in a sentence in a cell. e.g. " My Custom location is INNSA1" OR "I work at INMAA4" or "I want to go to INDEL6"
    – ajit maurya
    Nov 18 at 17:06










2




2




Heavy vote-down for shouting in all-capitals. Strongly suggest you edit.
– Michael Harvey
Nov 17 at 9:32




Heavy vote-down for shouting in all-capitals. Strongly suggest you edit.
– Michael Harvey
Nov 17 at 9:32












I don't really have a clear picture of your requirement. Are you looking for the presence (true/false) of a "word" (i.e., character string containing only alphanumerics--letters/numbers but no spaces or other kinds of characters), matching a pattern (starts with IN, and ends with 4, 1, 6, or b), which can be located anywhere in a "sentence" but delimited from it by space or punctuation, that is contained in a single cell? Is it always a separate "word" or can it be a character string embedded in a longer "word"? (cont'd)
– fixer1234
Nov 18 at 2:21




I don't really have a clear picture of your requirement. Are you looking for the presence (true/false) of a "word" (i.e., character string containing only alphanumerics--letters/numbers but no spaces or other kinds of characters), matching a pattern (starts with IN, and ends with 4, 1, 6, or b), which can be located anywhere in a "sentence" but delimited from it by space or punctuation, that is contained in a single cell? Is it always a separate "word" or can it be a character string embedded in a longer "word"? (cont'd)
– fixer1234
Nov 18 at 2:21












Is it always exactly 6 characters? Are the letters always uppercase? What do the "sentences" look like? Can the "word" appear more than once, including as part of a larger word? This would be easier to understand if you include examples of the sentences that represent the range of conditions.
– fixer1234
Nov 18 at 2:21




Is it always exactly 6 characters? Are the letters always uppercase? What do the "sentences" look like? Can the "word" appear more than once, including as part of a larger word? This would be easier to understand if you include examples of the sentences that represent the range of conditions.
– fixer1234
Nov 18 at 2:21












Also, as Gary's Student interpreted, is the word the only thing in the cell or is it somewhere within other text in a cell (which are very different requirements)?
– fixer1234
Nov 18 at 2:32




Also, as Gary's Student interpreted, is the word the only thing in the cell or is it somewhere within other text in a cell (which are very different requirements)?
– fixer1234
Nov 18 at 2:32












I want to search particular pattern in a sentence in a cell. e.g. " My Custom location is INNSA1" OR "I work at INMAA4" or "I want to go to INDEL6"
– ajit maurya
Nov 18 at 17:06






I want to search particular pattern in a sentence in a cell. e.g. " My Custom location is INNSA1" OR "I work at INMAA4" or "I want to go to INDEL6"
– ajit maurya
Nov 18 at 17:06












2 Answers
2






active

oldest

votes

















up vote
0
down vote













This is just an example that you can adapt to your schema.



With data from A2 to A26, in B2 enter:



=IF(AND(LEFT(A2,2)="IN",OR(RIGHT(A2,1)="B",RIGHT(A2,1)="1",RIGHT(A2,1)="4",RIGHT(A2,1)="6")),1+MAX($B$1:B1),"")


and copy downward:



enter image description here



As you see, each item of "good" data is marked with a simple sequential index.






share|improve this answer






























    up vote
    0
    down vote













    There are many ways to do each piece of the problem, but the combination of requirements points to one approach that is simple and straightforward, or a VBA solution. The non-VBA solution uses helper columns. The layout of your spreadsheet is unknown, as are other factors, like the number of sentences and the possible number of results, and how you need and want to use the results. So this answer will be more generic guidance than a specific solution.



    Using functions, it will be complicated to search the sentence for potentially more than one target. A simpler approach is to break the sentence into words and then check the words. A simple way to parse the sentences is with the built-in Convert Text To Columns wizard.



    Assuming the sentences are in column A, leave the next few columns blank for your results. That way, your results will always be in a known location, visible next to your data. I'll assume a maximum of two, so columns B and C will contain result values.



    Figure the maximum number of words there can be in a sentence, and reserve that many subsequent columns for helper columns. These will be used to test each word. Lets say you allow for five words. Columns D:H will contain formulas pointing to columns I:M, respectively.



    Lets say row 2 is your first data row, so the first formula will be in D2, pointing to I2. The formula will be similar to what Gary's Student suggested:



    =IF(AND(LEFT(I2,2)="IN",OR(RIGHT(I2,1)="B",RIGHT(I2,1)="1",RIGHT(I2,1)="4",RIGHT(I2,1)="6")),1,0)


    An alternate formula would be:



    =IFERROR((LEFT(I2,2)="IN")*(SEARCH(RIGHT(I2,1)," 416b")>1),0)


    That just gives you a couple of ideas about how to tell whether the target word fits the pattern. The second formula uses SEARCH (because it isn't case-sensitive), to see if the last character is in your list. Testing the first two characters for IN, and the last character, each result in True or False, which Excel treats as 1 and 0, respectively. So if both tests are true the result is 1, otherwise 0.



    In the SEARCH expression, I started with a blank and test for a result >1. The reason I did this is because I used MS Office Online to test it, and it thinks the rightmost character of an empty cell is found in position 1 of the test string.



    If SEARCH does not find a match, it returns an error, so wrapping the formula in IFERROR ensures that any word not matching results in 0.



    So either formula returns 1 if the word fits your pattern, or 0 if it doesn't (or if its target cell is empty).



    Enter either formula in D2, and drag or copy it across to H2, and down to the last row you need.



    To fill the target cells, select all the data in column A, and copy and paste it into column I (Text to Columns overwrites the data and starts in the data column). Select the data in column I. On the Data tab, in the Data Tools group, click Text to Columns. You'll get a wizard that is self-explanatory.



    Tell it the data is delimited, and select space as the delimiter. It will give you a preview of how it thinks you want it to parse the words. When you finish the wizard it will put each word in a consecutive cell in the row.



    Your formulas in D:H should show at least one 1 in each row. Those are your words, and their column is in the same relative position as the parsed word.



    To get the first word's value in column B, use INDEX and MATCH to find the first 1 in the row in D:H and retrieve the corresponding value from the same row in I:M. For example, B2 would be:



    =INDEX(I2:M2,MATCH(1,D2:H2,0))


    This retrieves the value from the cell in I2:M2 corresponding to where an exact match to 1 was found in D2:H2.



    To get the subsequent values for column C (and beyond if there are more than two), there are a number of solutions to find the Nth matching 1. Here is a link to one method.






    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      ajit maurya is a new contributor. Be nice, and check out our Code of Conduct.










       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376187%2flooking-for-formula-to-search-for-particular-pattern-in-excel%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      This is just an example that you can adapt to your schema.



      With data from A2 to A26, in B2 enter:



      =IF(AND(LEFT(A2,2)="IN",OR(RIGHT(A2,1)="B",RIGHT(A2,1)="1",RIGHT(A2,1)="4",RIGHT(A2,1)="6")),1+MAX($B$1:B1),"")


      and copy downward:



      enter image description here



      As you see, each item of "good" data is marked with a simple sequential index.






      share|improve this answer



























        up vote
        0
        down vote













        This is just an example that you can adapt to your schema.



        With data from A2 to A26, in B2 enter:



        =IF(AND(LEFT(A2,2)="IN",OR(RIGHT(A2,1)="B",RIGHT(A2,1)="1",RIGHT(A2,1)="4",RIGHT(A2,1)="6")),1+MAX($B$1:B1),"")


        and copy downward:



        enter image description here



        As you see, each item of "good" data is marked with a simple sequential index.






        share|improve this answer

























          up vote
          0
          down vote










          up vote
          0
          down vote









          This is just an example that you can adapt to your schema.



          With data from A2 to A26, in B2 enter:



          =IF(AND(LEFT(A2,2)="IN",OR(RIGHT(A2,1)="B",RIGHT(A2,1)="1",RIGHT(A2,1)="4",RIGHT(A2,1)="6")),1+MAX($B$1:B1),"")


          and copy downward:



          enter image description here



          As you see, each item of "good" data is marked with a simple sequential index.






          share|improve this answer














          This is just an example that you can adapt to your schema.



          With data from A2 to A26, in B2 enter:



          =IF(AND(LEFT(A2,2)="IN",OR(RIGHT(A2,1)="B",RIGHT(A2,1)="1",RIGHT(A2,1)="4",RIGHT(A2,1)="6")),1+MAX($B$1:B1),"")


          and copy downward:



          enter image description here



          As you see, each item of "good" data is marked with a simple sequential index.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 at 17:19

























          answered Nov 17 at 16:27









          Gary's Student

          13.2k31729




          13.2k31729
























              up vote
              0
              down vote













              There are many ways to do each piece of the problem, but the combination of requirements points to one approach that is simple and straightforward, or a VBA solution. The non-VBA solution uses helper columns. The layout of your spreadsheet is unknown, as are other factors, like the number of sentences and the possible number of results, and how you need and want to use the results. So this answer will be more generic guidance than a specific solution.



              Using functions, it will be complicated to search the sentence for potentially more than one target. A simpler approach is to break the sentence into words and then check the words. A simple way to parse the sentences is with the built-in Convert Text To Columns wizard.



              Assuming the sentences are in column A, leave the next few columns blank for your results. That way, your results will always be in a known location, visible next to your data. I'll assume a maximum of two, so columns B and C will contain result values.



              Figure the maximum number of words there can be in a sentence, and reserve that many subsequent columns for helper columns. These will be used to test each word. Lets say you allow for five words. Columns D:H will contain formulas pointing to columns I:M, respectively.



              Lets say row 2 is your first data row, so the first formula will be in D2, pointing to I2. The formula will be similar to what Gary's Student suggested:



              =IF(AND(LEFT(I2,2)="IN",OR(RIGHT(I2,1)="B",RIGHT(I2,1)="1",RIGHT(I2,1)="4",RIGHT(I2,1)="6")),1,0)


              An alternate formula would be:



              =IFERROR((LEFT(I2,2)="IN")*(SEARCH(RIGHT(I2,1)," 416b")>1),0)


              That just gives you a couple of ideas about how to tell whether the target word fits the pattern. The second formula uses SEARCH (because it isn't case-sensitive), to see if the last character is in your list. Testing the first two characters for IN, and the last character, each result in True or False, which Excel treats as 1 and 0, respectively. So if both tests are true the result is 1, otherwise 0.



              In the SEARCH expression, I started with a blank and test for a result >1. The reason I did this is because I used MS Office Online to test it, and it thinks the rightmost character of an empty cell is found in position 1 of the test string.



              If SEARCH does not find a match, it returns an error, so wrapping the formula in IFERROR ensures that any word not matching results in 0.



              So either formula returns 1 if the word fits your pattern, or 0 if it doesn't (or if its target cell is empty).



              Enter either formula in D2, and drag or copy it across to H2, and down to the last row you need.



              To fill the target cells, select all the data in column A, and copy and paste it into column I (Text to Columns overwrites the data and starts in the data column). Select the data in column I. On the Data tab, in the Data Tools group, click Text to Columns. You'll get a wizard that is self-explanatory.



              Tell it the data is delimited, and select space as the delimiter. It will give you a preview of how it thinks you want it to parse the words. When you finish the wizard it will put each word in a consecutive cell in the row.



              Your formulas in D:H should show at least one 1 in each row. Those are your words, and their column is in the same relative position as the parsed word.



              To get the first word's value in column B, use INDEX and MATCH to find the first 1 in the row in D:H and retrieve the corresponding value from the same row in I:M. For example, B2 would be:



              =INDEX(I2:M2,MATCH(1,D2:H2,0))


              This retrieves the value from the cell in I2:M2 corresponding to where an exact match to 1 was found in D2:H2.



              To get the subsequent values for column C (and beyond if there are more than two), there are a number of solutions to find the Nth matching 1. Here is a link to one method.






              share|improve this answer



























                up vote
                0
                down vote













                There are many ways to do each piece of the problem, but the combination of requirements points to one approach that is simple and straightforward, or a VBA solution. The non-VBA solution uses helper columns. The layout of your spreadsheet is unknown, as are other factors, like the number of sentences and the possible number of results, and how you need and want to use the results. So this answer will be more generic guidance than a specific solution.



                Using functions, it will be complicated to search the sentence for potentially more than one target. A simpler approach is to break the sentence into words and then check the words. A simple way to parse the sentences is with the built-in Convert Text To Columns wizard.



                Assuming the sentences are in column A, leave the next few columns blank for your results. That way, your results will always be in a known location, visible next to your data. I'll assume a maximum of two, so columns B and C will contain result values.



                Figure the maximum number of words there can be in a sentence, and reserve that many subsequent columns for helper columns. These will be used to test each word. Lets say you allow for five words. Columns D:H will contain formulas pointing to columns I:M, respectively.



                Lets say row 2 is your first data row, so the first formula will be in D2, pointing to I2. The formula will be similar to what Gary's Student suggested:



                =IF(AND(LEFT(I2,2)="IN",OR(RIGHT(I2,1)="B",RIGHT(I2,1)="1",RIGHT(I2,1)="4",RIGHT(I2,1)="6")),1,0)


                An alternate formula would be:



                =IFERROR((LEFT(I2,2)="IN")*(SEARCH(RIGHT(I2,1)," 416b")>1),0)


                That just gives you a couple of ideas about how to tell whether the target word fits the pattern. The second formula uses SEARCH (because it isn't case-sensitive), to see if the last character is in your list. Testing the first two characters for IN, and the last character, each result in True or False, which Excel treats as 1 and 0, respectively. So if both tests are true the result is 1, otherwise 0.



                In the SEARCH expression, I started with a blank and test for a result >1. The reason I did this is because I used MS Office Online to test it, and it thinks the rightmost character of an empty cell is found in position 1 of the test string.



                If SEARCH does not find a match, it returns an error, so wrapping the formula in IFERROR ensures that any word not matching results in 0.



                So either formula returns 1 if the word fits your pattern, or 0 if it doesn't (or if its target cell is empty).



                Enter either formula in D2, and drag or copy it across to H2, and down to the last row you need.



                To fill the target cells, select all the data in column A, and copy and paste it into column I (Text to Columns overwrites the data and starts in the data column). Select the data in column I. On the Data tab, in the Data Tools group, click Text to Columns. You'll get a wizard that is self-explanatory.



                Tell it the data is delimited, and select space as the delimiter. It will give you a preview of how it thinks you want it to parse the words. When you finish the wizard it will put each word in a consecutive cell in the row.



                Your formulas in D:H should show at least one 1 in each row. Those are your words, and their column is in the same relative position as the parsed word.



                To get the first word's value in column B, use INDEX and MATCH to find the first 1 in the row in D:H and retrieve the corresponding value from the same row in I:M. For example, B2 would be:



                =INDEX(I2:M2,MATCH(1,D2:H2,0))


                This retrieves the value from the cell in I2:M2 corresponding to where an exact match to 1 was found in D2:H2.



                To get the subsequent values for column C (and beyond if there are more than two), there are a number of solutions to find the Nth matching 1. Here is a link to one method.






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  There are many ways to do each piece of the problem, but the combination of requirements points to one approach that is simple and straightforward, or a VBA solution. The non-VBA solution uses helper columns. The layout of your spreadsheet is unknown, as are other factors, like the number of sentences and the possible number of results, and how you need and want to use the results. So this answer will be more generic guidance than a specific solution.



                  Using functions, it will be complicated to search the sentence for potentially more than one target. A simpler approach is to break the sentence into words and then check the words. A simple way to parse the sentences is with the built-in Convert Text To Columns wizard.



                  Assuming the sentences are in column A, leave the next few columns blank for your results. That way, your results will always be in a known location, visible next to your data. I'll assume a maximum of two, so columns B and C will contain result values.



                  Figure the maximum number of words there can be in a sentence, and reserve that many subsequent columns for helper columns. These will be used to test each word. Lets say you allow for five words. Columns D:H will contain formulas pointing to columns I:M, respectively.



                  Lets say row 2 is your first data row, so the first formula will be in D2, pointing to I2. The formula will be similar to what Gary's Student suggested:



                  =IF(AND(LEFT(I2,2)="IN",OR(RIGHT(I2,1)="B",RIGHT(I2,1)="1",RIGHT(I2,1)="4",RIGHT(I2,1)="6")),1,0)


                  An alternate formula would be:



                  =IFERROR((LEFT(I2,2)="IN")*(SEARCH(RIGHT(I2,1)," 416b")>1),0)


                  That just gives you a couple of ideas about how to tell whether the target word fits the pattern. The second formula uses SEARCH (because it isn't case-sensitive), to see if the last character is in your list. Testing the first two characters for IN, and the last character, each result in True or False, which Excel treats as 1 and 0, respectively. So if both tests are true the result is 1, otherwise 0.



                  In the SEARCH expression, I started with a blank and test for a result >1. The reason I did this is because I used MS Office Online to test it, and it thinks the rightmost character of an empty cell is found in position 1 of the test string.



                  If SEARCH does not find a match, it returns an error, so wrapping the formula in IFERROR ensures that any word not matching results in 0.



                  So either formula returns 1 if the word fits your pattern, or 0 if it doesn't (or if its target cell is empty).



                  Enter either formula in D2, and drag or copy it across to H2, and down to the last row you need.



                  To fill the target cells, select all the data in column A, and copy and paste it into column I (Text to Columns overwrites the data and starts in the data column). Select the data in column I. On the Data tab, in the Data Tools group, click Text to Columns. You'll get a wizard that is self-explanatory.



                  Tell it the data is delimited, and select space as the delimiter. It will give you a preview of how it thinks you want it to parse the words. When you finish the wizard it will put each word in a consecutive cell in the row.



                  Your formulas in D:H should show at least one 1 in each row. Those are your words, and their column is in the same relative position as the parsed word.



                  To get the first word's value in column B, use INDEX and MATCH to find the first 1 in the row in D:H and retrieve the corresponding value from the same row in I:M. For example, B2 would be:



                  =INDEX(I2:M2,MATCH(1,D2:H2,0))


                  This retrieves the value from the cell in I2:M2 corresponding to where an exact match to 1 was found in D2:H2.



                  To get the subsequent values for column C (and beyond if there are more than two), there are a number of solutions to find the Nth matching 1. Here is a link to one method.






                  share|improve this answer














                  There are many ways to do each piece of the problem, but the combination of requirements points to one approach that is simple and straightforward, or a VBA solution. The non-VBA solution uses helper columns. The layout of your spreadsheet is unknown, as are other factors, like the number of sentences and the possible number of results, and how you need and want to use the results. So this answer will be more generic guidance than a specific solution.



                  Using functions, it will be complicated to search the sentence for potentially more than one target. A simpler approach is to break the sentence into words and then check the words. A simple way to parse the sentences is with the built-in Convert Text To Columns wizard.



                  Assuming the sentences are in column A, leave the next few columns blank for your results. That way, your results will always be in a known location, visible next to your data. I'll assume a maximum of two, so columns B and C will contain result values.



                  Figure the maximum number of words there can be in a sentence, and reserve that many subsequent columns for helper columns. These will be used to test each word. Lets say you allow for five words. Columns D:H will contain formulas pointing to columns I:M, respectively.



                  Lets say row 2 is your first data row, so the first formula will be in D2, pointing to I2. The formula will be similar to what Gary's Student suggested:



                  =IF(AND(LEFT(I2,2)="IN",OR(RIGHT(I2,1)="B",RIGHT(I2,1)="1",RIGHT(I2,1)="4",RIGHT(I2,1)="6")),1,0)


                  An alternate formula would be:



                  =IFERROR((LEFT(I2,2)="IN")*(SEARCH(RIGHT(I2,1)," 416b")>1),0)


                  That just gives you a couple of ideas about how to tell whether the target word fits the pattern. The second formula uses SEARCH (because it isn't case-sensitive), to see if the last character is in your list. Testing the first two characters for IN, and the last character, each result in True or False, which Excel treats as 1 and 0, respectively. So if both tests are true the result is 1, otherwise 0.



                  In the SEARCH expression, I started with a blank and test for a result >1. The reason I did this is because I used MS Office Online to test it, and it thinks the rightmost character of an empty cell is found in position 1 of the test string.



                  If SEARCH does not find a match, it returns an error, so wrapping the formula in IFERROR ensures that any word not matching results in 0.



                  So either formula returns 1 if the word fits your pattern, or 0 if it doesn't (or if its target cell is empty).



                  Enter either formula in D2, and drag or copy it across to H2, and down to the last row you need.



                  To fill the target cells, select all the data in column A, and copy and paste it into column I (Text to Columns overwrites the data and starts in the data column). Select the data in column I. On the Data tab, in the Data Tools group, click Text to Columns. You'll get a wizard that is self-explanatory.



                  Tell it the data is delimited, and select space as the delimiter. It will give you a preview of how it thinks you want it to parse the words. When you finish the wizard it will put each word in a consecutive cell in the row.



                  Your formulas in D:H should show at least one 1 in each row. Those are your words, and their column is in the same relative position as the parsed word.



                  To get the first word's value in column B, use INDEX and MATCH to find the first 1 in the row in D:H and retrieve the corresponding value from the same row in I:M. For example, B2 would be:



                  =INDEX(I2:M2,MATCH(1,D2:H2,0))


                  This retrieves the value from the cell in I2:M2 corresponding to where an exact match to 1 was found in D2:H2.



                  To get the subsequent values for column C (and beyond if there are more than two), there are a number of solutions to find the Nth matching 1. Here is a link to one method.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 20 at 9:39

























                  answered Nov 20 at 9:20









                  fixer1234

                  17.3k144280




                  17.3k144280






















                      ajit maurya is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      ajit maurya is a new contributor. Be nice, and check out our Code of Conduct.













                      ajit maurya is a new contributor. Be nice, and check out our Code of Conduct.












                      ajit maurya is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376187%2flooking-for-formula-to-search-for-particular-pattern-in-excel%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      AnyDesk - Fatal Program Failure

                      How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

                      QoS: MAC-Priority for clients behind a repeater