Multiple if search statements in excel?










-1















I am trying to convert text of the month to the number



B2 cell:



BirthMonth_Jan



BirthMonth_Feb



BirthMonth_mar



BirthMonth_Apr



BirthMonth_May



BirthMonth_Jun, ect to december



for example, BirthMonth_Jan will output 1 based on the search of Jan, so i can compare this to another set of numbers



I have this, and tried this, but only works with two if statements, is there anyway i can do this with 12?



=(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))


I get #Value!



If i try this, it also doesn't work



=IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))


the second option only works with two but if i add more it throws an error










share|improve this question


























    -1















    I am trying to convert text of the month to the number



    B2 cell:



    BirthMonth_Jan



    BirthMonth_Feb



    BirthMonth_mar



    BirthMonth_Apr



    BirthMonth_May



    BirthMonth_Jun, ect to december



    for example, BirthMonth_Jan will output 1 based on the search of Jan, so i can compare this to another set of numbers



    I have this, and tried this, but only works with two if statements, is there anyway i can do this with 12?



    =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))


    I get #Value!



    If i try this, it also doesn't work



    =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))


    the second option only works with two but if i add more it throws an error










    share|improve this question
























      -1












      -1








      -1


      0






      I am trying to convert text of the month to the number



      B2 cell:



      BirthMonth_Jan



      BirthMonth_Feb



      BirthMonth_mar



      BirthMonth_Apr



      BirthMonth_May



      BirthMonth_Jun, ect to december



      for example, BirthMonth_Jan will output 1 based on the search of Jan, so i can compare this to another set of numbers



      I have this, and tried this, but only works with two if statements, is there anyway i can do this with 12?



      =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))


      I get #Value!



      If i try this, it also doesn't work



      =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))


      the second option only works with two but if i add more it throws an error










      share|improve this question














      I am trying to convert text of the month to the number



      B2 cell:



      BirthMonth_Jan



      BirthMonth_Feb



      BirthMonth_mar



      BirthMonth_Apr



      BirthMonth_May



      BirthMonth_Jun, ect to december



      for example, BirthMonth_Jan will output 1 based on the search of Jan, so i can compare this to another set of numbers



      I have this, and tried this, but only works with two if statements, is there anyway i can do this with 12?



      =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))


      I get #Value!



      If i try this, it also doesn't work



      =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))


      the second option only works with two but if i add more it throws an error







      excel if-statement statements






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 20:18









      gbdavidxgbdavidx

      1




      1






















          3 Answers
          3






          active

          oldest

          votes


















          0














          Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :



          =MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))



          enter image description here



          Having a view of your data and expected result would help if this is not what you're after.






          share|improve this answer























          • Not sure if this would work, forgot to mention i have other text in the field i can't parse out

            – gbdavidx
            Nov 15 '18 at 21:03











          • I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

            – gbdavidx
            Nov 15 '18 at 21:03











          • trying to export the birth month only based on search criteria

            – gbdavidx
            Nov 15 '18 at 21:05


















          0














          It is seems just possible what you might want is:



          =MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)


          Returns a Number.






          share|improve this answer






























            0














            The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive



            Two formula are offered:



            Formula 1
            =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))



            The questioner said "I get #Value!"

            This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
            However, if the if statements were nested, then the formula would work. Something along these lines:
            =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))



            Formula 2
            =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))



            So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.



            Failure is caused by two things:

            1) The double bracket following "11")) in the "November" search. There should be zero brackets here.

            2) The formula needs an additional closing bracket.



            Two other things to note:

            1) in the event of a match, the value returned is a string not an integer.

            2) there's no provision to return a value in the event of a failure to match.



            Working IF statement formula

            The following formula, consisting of nested IF statements, works as intended by the questioner.
            =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))



            Note, the formula uses the NA() function to return #N/A if there is no match.



            VLOOKUP alternative

            Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
            =VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)

            Using January as an example: BirthMonth_Jan, the formula lookup works like this:
            RIGHT(B2,LEN(B2)-SEARCH("_",B2))

            1) search for the underline character SEARCH("_",B2),

            2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.

            3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value

            4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).

            5) If there is no valid result, VLOOKUP automatically returns #N/A.




            The reference table on a separate sheet:
            Month name lookup table






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              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',
              autoActivateHeartbeat: false,
              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
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327290%2fmultiple-if-search-statements-in-excel%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :



              =MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))



              enter image description here



              Having a view of your data and expected result would help if this is not what you're after.






              share|improve this answer























              • Not sure if this would work, forgot to mention i have other text in the field i can't parse out

                – gbdavidx
                Nov 15 '18 at 21:03











              • I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

                – gbdavidx
                Nov 15 '18 at 21:03











              • trying to export the birth month only based on search criteria

                – gbdavidx
                Nov 15 '18 at 21:05















              0














              Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :



              =MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))



              enter image description here



              Having a view of your data and expected result would help if this is not what you're after.






              share|improve this answer























              • Not sure if this would work, forgot to mention i have other text in the field i can't parse out

                – gbdavidx
                Nov 15 '18 at 21:03











              • I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

                – gbdavidx
                Nov 15 '18 at 21:03











              • trying to export the birth month only based on search criteria

                – gbdavidx
                Nov 15 '18 at 21:05













              0












              0








              0







              Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :



              =MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))



              enter image description here



              Having a view of your data and expected result would help if this is not what you're after.






              share|improve this answer













              Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :



              =MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))



              enter image description here



              Having a view of your data and expected result would help if this is not what you're after.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 15 '18 at 20:39









              Display nameDisplay name

              53416




              53416












              • Not sure if this would work, forgot to mention i have other text in the field i can't parse out

                – gbdavidx
                Nov 15 '18 at 21:03











              • I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

                – gbdavidx
                Nov 15 '18 at 21:03











              • trying to export the birth month only based on search criteria

                – gbdavidx
                Nov 15 '18 at 21:05

















              • Not sure if this would work, forgot to mention i have other text in the field i can't parse out

                – gbdavidx
                Nov 15 '18 at 21:03











              • I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

                – gbdavidx
                Nov 15 '18 at 21:03











              • trying to export the birth month only based on search criteria

                – gbdavidx
                Nov 15 '18 at 21:05
















              Not sure if this would work, forgot to mention i have other text in the field i can't parse out

              – gbdavidx
              Nov 15 '18 at 21:03





              Not sure if this would work, forgot to mention i have other text in the field i can't parse out

              – gbdavidx
              Nov 15 '18 at 21:03













              I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

              – gbdavidx
              Nov 15 '18 at 21:03





              I found this, that may be a solution, if i can get it working, myonlinetraininghub.com/excel-search-string-for-a-list-of-words

              – gbdavidx
              Nov 15 '18 at 21:03













              trying to export the birth month only based on search criteria

              – gbdavidx
              Nov 15 '18 at 21:05





              trying to export the birth month only based on search criteria

              – gbdavidx
              Nov 15 '18 at 21:05













              0














              It is seems just possible what you might want is:



              =MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)


              Returns a Number.






              share|improve this answer



























                0














                It is seems just possible what you might want is:



                =MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)


                Returns a Number.






                share|improve this answer

























                  0












                  0








                  0







                  It is seems just possible what you might want is:



                  =MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)


                  Returns a Number.






                  share|improve this answer













                  It is seems just possible what you might want is:



                  =MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)


                  Returns a Number.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 22:09









                  pnutspnuts

                  49.1k764101




                  49.1k764101





















                      0














                      The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive



                      Two formula are offered:



                      Formula 1
                      =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))



                      The questioner said "I get #Value!"

                      This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
                      However, if the if statements were nested, then the formula would work. Something along these lines:
                      =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))



                      Formula 2
                      =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))



                      So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.



                      Failure is caused by two things:

                      1) The double bracket following "11")) in the "November" search. There should be zero brackets here.

                      2) The formula needs an additional closing bracket.



                      Two other things to note:

                      1) in the event of a match, the value returned is a string not an integer.

                      2) there's no provision to return a value in the event of a failure to match.



                      Working IF statement formula

                      The following formula, consisting of nested IF statements, works as intended by the questioner.
                      =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))



                      Note, the formula uses the NA() function to return #N/A if there is no match.



                      VLOOKUP alternative

                      Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
                      =VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)

                      Using January as an example: BirthMonth_Jan, the formula lookup works like this:
                      RIGHT(B2,LEN(B2)-SEARCH("_",B2))

                      1) search for the underline character SEARCH("_",B2),

                      2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.

                      3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value

                      4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).

                      5) If there is no valid result, VLOOKUP automatically returns #N/A.




                      The reference table on a separate sheet:
                      Month name lookup table






                      share|improve this answer



























                        0














                        The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive



                        Two formula are offered:



                        Formula 1
                        =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))



                        The questioner said "I get #Value!"

                        This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
                        However, if the if statements were nested, then the formula would work. Something along these lines:
                        =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))



                        Formula 2
                        =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))



                        So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.



                        Failure is caused by two things:

                        1) The double bracket following "11")) in the "November" search. There should be zero brackets here.

                        2) The formula needs an additional closing bracket.



                        Two other things to note:

                        1) in the event of a match, the value returned is a string not an integer.

                        2) there's no provision to return a value in the event of a failure to match.



                        Working IF statement formula

                        The following formula, consisting of nested IF statements, works as intended by the questioner.
                        =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))



                        Note, the formula uses the NA() function to return #N/A if there is no match.



                        VLOOKUP alternative

                        Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
                        =VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)

                        Using January as an example: BirthMonth_Jan, the formula lookup works like this:
                        RIGHT(B2,LEN(B2)-SEARCH("_",B2))

                        1) search for the underline character SEARCH("_",B2),

                        2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.

                        3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value

                        4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).

                        5) If there is no valid result, VLOOKUP automatically returns #N/A.




                        The reference table on a separate sheet:
                        Month name lookup table






                        share|improve this answer

























                          0












                          0








                          0







                          The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive



                          Two formula are offered:



                          Formula 1
                          =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))



                          The questioner said "I get #Value!"

                          This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
                          However, if the if statements were nested, then the formula would work. Something along these lines:
                          =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))



                          Formula 2
                          =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))



                          So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.



                          Failure is caused by two things:

                          1) The double bracket following "11")) in the "November" search. There should be zero brackets here.

                          2) The formula needs an additional closing bracket.



                          Two other things to note:

                          1) in the event of a match, the value returned is a string not an integer.

                          2) there's no provision to return a value in the event of a failure to match.



                          Working IF statement formula

                          The following formula, consisting of nested IF statements, works as intended by the questioner.
                          =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))



                          Note, the formula uses the NA() function to return #N/A if there is no match.



                          VLOOKUP alternative

                          Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
                          =VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)

                          Using January as an example: BirthMonth_Jan, the formula lookup works like this:
                          RIGHT(B2,LEN(B2)-SEARCH("_",B2))

                          1) search for the underline character SEARCH("_",B2),

                          2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.

                          3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value

                          4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).

                          5) If there is no valid result, VLOOKUP automatically returns #N/A.




                          The reference table on a separate sheet:
                          Month name lookup table






                          share|improve this answer













                          The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive



                          Two formula are offered:



                          Formula 1
                          =(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))



                          The questioner said "I get #Value!"

                          This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
                          However, if the if statements were nested, then the formula would work. Something along these lines:
                          =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))



                          Formula 2
                          =IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))



                          So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.



                          Failure is caused by two things:

                          1) The double bracket following "11")) in the "November" search. There should be zero brackets here.

                          2) The formula needs an additional closing bracket.



                          Two other things to note:

                          1) in the event of a match, the value returned is a string not an integer.

                          2) there's no provision to return a value in the event of a failure to match.



                          Working IF statement formula

                          The following formula, consisting of nested IF statements, works as intended by the questioner.
                          =IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))



                          Note, the formula uses the NA() function to return #N/A if there is no match.



                          VLOOKUP alternative

                          Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
                          =VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)

                          Using January as an example: BirthMonth_Jan, the formula lookup works like this:
                          RIGHT(B2,LEN(B2)-SEARCH("_",B2))

                          1) search for the underline character SEARCH("_",B2),

                          2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.

                          3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value

                          4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).

                          5) If there is no valid result, VLOOKUP automatically returns #N/A.




                          The reference table on a separate sheet:
                          Month name lookup table







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '18 at 23:43









                          TedinozTedinoz

                          1,27521319




                          1,27521319



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327290%2fmultiple-if-search-statements-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







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3

                              Museum of Modern and Contemporary Art of Trento and Rovereto