How can I do a two dimensional lookup where the column and row headers are ranges?Find the different two...

How to generate globally unique ids for different tables of the same database?

Brexit - No Deal Rejection

Happy pi day, everyone!

At what level can a dragon innately cast its spells?

PTIJ: Who should pay for Uber rides: the child or the parent?

Old race car problem/puzzle

Why are the outputs of printf and std::cout different

Humanity loses the vast majority of its technology, information, and population in the year 2122. How long does it take to rebuild itself?

RegionDifference for Cylinder and Cuboid

How do anti-virus programs start at Windows boot?

What are the possible solutions of the given equation?

Informing my boss about remarks from a nasty colleague

Where is the 1/8 CR apprentice in Volo's Guide to Monsters?

SQL Server Primary Login Restrictions

Be in awe of my brilliance!

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

An Accountant Seeks the Help of a Mathematician

How could a female member of a species produce eggs unto death?

Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements

Possible Leak In Concrete

Can hydraulic brake levers get hot when brakes overheat?

Is it true that real estate prices mainly go up?

Could the Saturn V actually have launched astronauts around Venus?

Am I not good enough for you?



How can I do a two dimensional lookup where the column and row headers are ranges?


Find the different two Excel sheets when having identical rowExcel, how to use text functions on lookup array without putting in another column?How to make excel SUMUP values of multiple rowkeys in a two-dimensional lookup to return sumed up values in a corresponding cellWhat's VLOOKUP's true algorithm with range_lookup set to TRUE?Return index number of matching item in arrayHow can I combine VLOOKUP within an IF statement where the column index of the VLOOKUP function is a number extrapolated from a text?Excel: lookup with variable row AND columnVLOOKUP: lookup_value isn't in first column of table_arrayHow to return column headers based on VLOOKUP result?Match a column header (of nonspecific location) against column contents, and get all row headers













0















I have spreadsheet that has a table that is similar in structure to this:



      | 1-2 | 3-4 | 5-6 | 7+
-------------------------------
18-20 | 7 | 2 | 9 | 4 |
21-25 | 1 | 0 | 6 | 3 |
26-30 | 1 | 4 | 6 | 9 |
31+ | 3 | 8 | 5 | 0 |


So say for example, the inputs I got from the user were 2, 19, the lookup should return 7. Or if the inputs were 9, 29, the lookup should return 9.



I know you can do two dimensional lookups when you just have single values in the row and column headers by combining VLOOKUP and MATCH. But how do I do the lookup when the headers are a range of values?



Do I need to just write a custom VBA function or does Excel have some built-in way to do this?










share|improve this question



























    0















    I have spreadsheet that has a table that is similar in structure to this:



          | 1-2 | 3-4 | 5-6 | 7+
    -------------------------------
    18-20 | 7 | 2 | 9 | 4 |
    21-25 | 1 | 0 | 6 | 3 |
    26-30 | 1 | 4 | 6 | 9 |
    31+ | 3 | 8 | 5 | 0 |


    So say for example, the inputs I got from the user were 2, 19, the lookup should return 7. Or if the inputs were 9, 29, the lookup should return 9.



    I know you can do two dimensional lookups when you just have single values in the row and column headers by combining VLOOKUP and MATCH. But how do I do the lookup when the headers are a range of values?



    Do I need to just write a custom VBA function or does Excel have some built-in way to do this?










    share|improve this question

























      0












      0








      0








      I have spreadsheet that has a table that is similar in structure to this:



            | 1-2 | 3-4 | 5-6 | 7+
      -------------------------------
      18-20 | 7 | 2 | 9 | 4 |
      21-25 | 1 | 0 | 6 | 3 |
      26-30 | 1 | 4 | 6 | 9 |
      31+ | 3 | 8 | 5 | 0 |


      So say for example, the inputs I got from the user were 2, 19, the lookup should return 7. Or if the inputs were 9, 29, the lookup should return 9.



      I know you can do two dimensional lookups when you just have single values in the row and column headers by combining VLOOKUP and MATCH. But how do I do the lookup when the headers are a range of values?



      Do I need to just write a custom VBA function or does Excel have some built-in way to do this?










      share|improve this question














      I have spreadsheet that has a table that is similar in structure to this:



            | 1-2 | 3-4 | 5-6 | 7+
      -------------------------------
      18-20 | 7 | 2 | 9 | 4 |
      21-25 | 1 | 0 | 6 | 3 |
      26-30 | 1 | 4 | 6 | 9 |
      31+ | 3 | 8 | 5 | 0 |


      So say for example, the inputs I got from the user were 2, 19, the lookup should return 7. Or if the inputs were 9, 29, the lookup should return 9.



      I know you can do two dimensional lookups when you just have single values in the row and column headers by combining VLOOKUP and MATCH. But how do I do the lookup when the headers are a range of values?



      Do I need to just write a custom VBA function or does Excel have some built-in way to do this?







      microsoft-excel worksheet-function vlookup






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 10 '18 at 23:20









      Lews TherinLews Therin

      1034




      1034






















          3 Answers
          3






          active

          oldest

          votes


















          1














          INDEX() can do a two-dimensional lookup. The syntax is INDEX(array,row_num,[col_num],[area_num]). It takes a 2D array and returns the intersection of row_num and column_num.



          Your problem is a bit tricky because of the ranges in the headers, but some fast footwork with TRUNC() and IF() does the job. This formula filled down from D8 in the screenshot below, gives the results shown:



          =INDEX(B$2:E$5,IF(C8>31,4,TRUNC((C8-11)/5)),IF(B8>7,4,TRUNC((B8+1)/2)))



          enter image description here



          If you want to see how the TRUNC() portion works, put =TRUNC((ROW()-11)/5) in row 18 or TRUNC((ROW()+1)/2) in row 1 and fill down.



          I hope this helps, and good luck.






          share|improve this answer

































            0














            Given that you are looking in ranges that are mutually exclusive and complete (at least for values >=18), your range can be defined by the first value in each cell. For example, the table you provide can be described equivalently by:



            enter image description here



            You can then find your value by combining vlookup and match. For example if your table and lookup values were arranged like the following picture:



            enter image description here



            Your desired value would be in the highlighted cell which would contain the following: =VLOOKUP(B$8,$A$1:$E$5, MATCH($A8,$A$1:$E$1,1),TRUE)






            share|improve this answer





















            • 1





              Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

              – Bandersnatch
              Feb 11 '18 at 2:09













            • @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

              – AlRacoon
              Feb 11 '18 at 2:16





















            0














            Since the labels are well-formed, which in the case of labels means, basically, they are ordered as if they had been sorted low-to-high by their first characters' character codes, one can take advantage of the last argument in VLOOKUP() and HLOOKUP(), taking the "approximate match" choice.



            You do this to create the lookup value and the column to look in for a VLOOKUP() which will do the final work.



            In the end, you have a simple VLOOKUP(). What to look up in it? Let's say your table shown is A1:E5 with its row labels in A2:A5 (DO NOT include that first row!) and its column labels being in B1:E1 (DO NOT include that first column!) and its actual data in B2:E5. If you include those first rows and columns (A1's), you will get the #N/A error. And let's say you handle obtaining the input values yourself, so however the "2, 19" material is created is however it is made available (I'll call it "Column to look in" and "Row to look in".) Then:



            =HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE )


            will return "18-20" which we will use directly as the lookup value, and



            =VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )


            will return "1-2" and here is where the "slight trick" comes in.



            If we wrap that last function in a MATCH() function, it uses the "1-2" to find the column number to look in which the final VLOOKUP() requires. (An anonymous person on Excel's UserVoice site showed me this.)



            You must now use the range we just avoided, A1:E1, to get the column number directly. If you begin it with B1, you have to add a "1" to the result, so this is simpler to read and understand:



            =MATCH(  VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )  , A1:E1 )


            which returns "2" for the column (coincidentally, nothing more, the same as our input, but admit no confusion into your game!). So finally, you will put it all together as:



            =VLOOKUP( HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE ) , A1:E5 , MATCH( VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE ) , A1:E1 ) , FALSE )


            Use "FALSE" for it because you either have exact matches available, or something has gone BADLY wrong.



            (If only the columns, or only the rows are amenable, you can still adapt here. You just have a harder time because only half of it is solved with this, but that can be enough, I have found. I've used it maybe 6-8 times since I learned the MATCH() idea to regain the row/column headers as Labels functionality and half of them only one was "ruly".)





            share








            New contributor




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




















              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',
              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%2fsuperuser.com%2fquestions%2f1293852%2fhow-can-i-do-a-two-dimensional-lookup-where-the-column-and-row-headers-are-range%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









              1














              INDEX() can do a two-dimensional lookup. The syntax is INDEX(array,row_num,[col_num],[area_num]). It takes a 2D array and returns the intersection of row_num and column_num.



              Your problem is a bit tricky because of the ranges in the headers, but some fast footwork with TRUNC() and IF() does the job. This formula filled down from D8 in the screenshot below, gives the results shown:



              =INDEX(B$2:E$5,IF(C8>31,4,TRUNC((C8-11)/5)),IF(B8>7,4,TRUNC((B8+1)/2)))



              enter image description here



              If you want to see how the TRUNC() portion works, put =TRUNC((ROW()-11)/5) in row 18 or TRUNC((ROW()+1)/2) in row 1 and fill down.



              I hope this helps, and good luck.






              share|improve this answer






























                1














                INDEX() can do a two-dimensional lookup. The syntax is INDEX(array,row_num,[col_num],[area_num]). It takes a 2D array and returns the intersection of row_num and column_num.



                Your problem is a bit tricky because of the ranges in the headers, but some fast footwork with TRUNC() and IF() does the job. This formula filled down from D8 in the screenshot below, gives the results shown:



                =INDEX(B$2:E$5,IF(C8>31,4,TRUNC((C8-11)/5)),IF(B8>7,4,TRUNC((B8+1)/2)))



                enter image description here



                If you want to see how the TRUNC() portion works, put =TRUNC((ROW()-11)/5) in row 18 or TRUNC((ROW()+1)/2) in row 1 and fill down.



                I hope this helps, and good luck.






                share|improve this answer




























                  1












                  1








                  1







                  INDEX() can do a two-dimensional lookup. The syntax is INDEX(array,row_num,[col_num],[area_num]). It takes a 2D array and returns the intersection of row_num and column_num.



                  Your problem is a bit tricky because of the ranges in the headers, but some fast footwork with TRUNC() and IF() does the job. This formula filled down from D8 in the screenshot below, gives the results shown:



                  =INDEX(B$2:E$5,IF(C8>31,4,TRUNC((C8-11)/5)),IF(B8>7,4,TRUNC((B8+1)/2)))



                  enter image description here



                  If you want to see how the TRUNC() portion works, put =TRUNC((ROW()-11)/5) in row 18 or TRUNC((ROW()+1)/2) in row 1 and fill down.



                  I hope this helps, and good luck.






                  share|improve this answer















                  INDEX() can do a two-dimensional lookup. The syntax is INDEX(array,row_num,[col_num],[area_num]). It takes a 2D array and returns the intersection of row_num and column_num.



                  Your problem is a bit tricky because of the ranges in the headers, but some fast footwork with TRUNC() and IF() does the job. This formula filled down from D8 in the screenshot below, gives the results shown:



                  =INDEX(B$2:E$5,IF(C8>31,4,TRUNC((C8-11)/5)),IF(B8>7,4,TRUNC((B8+1)/2)))



                  enter image description here



                  If you want to see how the TRUNC() portion works, put =TRUNC((ROW()-11)/5) in row 18 or TRUNC((ROW()+1)/2) in row 1 and fill down.



                  I hope this helps, and good luck.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 11 '18 at 2:12

























                  answered Feb 11 '18 at 1:54









                  BandersnatchBandersnatch

                  3,3752413




                  3,3752413

























                      0














                      Given that you are looking in ranges that are mutually exclusive and complete (at least for values >=18), your range can be defined by the first value in each cell. For example, the table you provide can be described equivalently by:



                      enter image description here



                      You can then find your value by combining vlookup and match. For example if your table and lookup values were arranged like the following picture:



                      enter image description here



                      Your desired value would be in the highlighted cell which would contain the following: =VLOOKUP(B$8,$A$1:$E$5, MATCH($A8,$A$1:$E$1,1),TRUE)






                      share|improve this answer





















                      • 1





                        Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

                        – Bandersnatch
                        Feb 11 '18 at 2:09













                      • @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

                        – AlRacoon
                        Feb 11 '18 at 2:16


















                      0














                      Given that you are looking in ranges that are mutually exclusive and complete (at least for values >=18), your range can be defined by the first value in each cell. For example, the table you provide can be described equivalently by:



                      enter image description here



                      You can then find your value by combining vlookup and match. For example if your table and lookup values were arranged like the following picture:



                      enter image description here



                      Your desired value would be in the highlighted cell which would contain the following: =VLOOKUP(B$8,$A$1:$E$5, MATCH($A8,$A$1:$E$1,1),TRUE)






                      share|improve this answer





















                      • 1





                        Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

                        – Bandersnatch
                        Feb 11 '18 at 2:09













                      • @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

                        – AlRacoon
                        Feb 11 '18 at 2:16
















                      0












                      0








                      0







                      Given that you are looking in ranges that are mutually exclusive and complete (at least for values >=18), your range can be defined by the first value in each cell. For example, the table you provide can be described equivalently by:



                      enter image description here



                      You can then find your value by combining vlookup and match. For example if your table and lookup values were arranged like the following picture:



                      enter image description here



                      Your desired value would be in the highlighted cell which would contain the following: =VLOOKUP(B$8,$A$1:$E$5, MATCH($A8,$A$1:$E$1,1),TRUE)






                      share|improve this answer















                      Given that you are looking in ranges that are mutually exclusive and complete (at least for values >=18), your range can be defined by the first value in each cell. For example, the table you provide can be described equivalently by:



                      enter image description here



                      You can then find your value by combining vlookup and match. For example if your table and lookup values were arranged like the following picture:



                      enter image description here



                      Your desired value would be in the highlighted cell which would contain the following: =VLOOKUP(B$8,$A$1:$E$5, MATCH($A8,$A$1:$E$1,1),TRUE)







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 11 '18 at 5:17

























                      answered Feb 11 '18 at 2:01









                      AlRacoonAlRacoon

                      1847




                      1847








                      • 1





                        Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

                        – Bandersnatch
                        Feb 11 '18 at 2:09













                      • @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

                        – AlRacoon
                        Feb 11 '18 at 2:16
















                      • 1





                        Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

                        – Bandersnatch
                        Feb 11 '18 at 2:09













                      • @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

                        – AlRacoon
                        Feb 11 '18 at 2:16










                      1




                      1





                      Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

                      – Bandersnatch
                      Feb 11 '18 at 2:09







                      Presumably the OP has the ranges in his headers for a reason, and would like to keep them there. But nice job using MATCH type 1 and VLOOKUP() with an approximate match to handle cases when the lookup value is out of range.

                      – Bandersnatch
                      Feb 11 '18 at 2:09















                      @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

                      – AlRacoon
                      Feb 11 '18 at 2:16







                      @Bandersnatch Thanks. I liked your approach as well. Had I seen it before I had posted my answer I most likely wouldn't have posted. The difficulty is that OP would have to do the calculation and nested if statements if there were more ranges that were not of equivalent size. Anyway, I think one or both of these approaches could be used by the OP, depending on their circumstances.

                      – AlRacoon
                      Feb 11 '18 at 2:16













                      0














                      Since the labels are well-formed, which in the case of labels means, basically, they are ordered as if they had been sorted low-to-high by their first characters' character codes, one can take advantage of the last argument in VLOOKUP() and HLOOKUP(), taking the "approximate match" choice.



                      You do this to create the lookup value and the column to look in for a VLOOKUP() which will do the final work.



                      In the end, you have a simple VLOOKUP(). What to look up in it? Let's say your table shown is A1:E5 with its row labels in A2:A5 (DO NOT include that first row!) and its column labels being in B1:E1 (DO NOT include that first column!) and its actual data in B2:E5. If you include those first rows and columns (A1's), you will get the #N/A error. And let's say you handle obtaining the input values yourself, so however the "2, 19" material is created is however it is made available (I'll call it "Column to look in" and "Row to look in".) Then:



                      =HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE )


                      will return "18-20" which we will use directly as the lookup value, and



                      =VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )


                      will return "1-2" and here is where the "slight trick" comes in.



                      If we wrap that last function in a MATCH() function, it uses the "1-2" to find the column number to look in which the final VLOOKUP() requires. (An anonymous person on Excel's UserVoice site showed me this.)



                      You must now use the range we just avoided, A1:E1, to get the column number directly. If you begin it with B1, you have to add a "1" to the result, so this is simpler to read and understand:



                      =MATCH(  VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )  , A1:E1 )


                      which returns "2" for the column (coincidentally, nothing more, the same as our input, but admit no confusion into your game!). So finally, you will put it all together as:



                      =VLOOKUP( HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE ) , A1:E5 , MATCH( VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE ) , A1:E1 ) , FALSE )


                      Use "FALSE" for it because you either have exact matches available, or something has gone BADLY wrong.



                      (If only the columns, or only the rows are amenable, you can still adapt here. You just have a harder time because only half of it is solved with this, but that can be enough, I have found. I've used it maybe 6-8 times since I learned the MATCH() idea to regain the row/column headers as Labels functionality and half of them only one was "ruly".)





                      share








                      New contributor




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

























                        0














                        Since the labels are well-formed, which in the case of labels means, basically, they are ordered as if they had been sorted low-to-high by their first characters' character codes, one can take advantage of the last argument in VLOOKUP() and HLOOKUP(), taking the "approximate match" choice.



                        You do this to create the lookup value and the column to look in for a VLOOKUP() which will do the final work.



                        In the end, you have a simple VLOOKUP(). What to look up in it? Let's say your table shown is A1:E5 with its row labels in A2:A5 (DO NOT include that first row!) and its column labels being in B1:E1 (DO NOT include that first column!) and its actual data in B2:E5. If you include those first rows and columns (A1's), you will get the #N/A error. And let's say you handle obtaining the input values yourself, so however the "2, 19" material is created is however it is made available (I'll call it "Column to look in" and "Row to look in".) Then:



                        =HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE )


                        will return "18-20" which we will use directly as the lookup value, and



                        =VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )


                        will return "1-2" and here is where the "slight trick" comes in.



                        If we wrap that last function in a MATCH() function, it uses the "1-2" to find the column number to look in which the final VLOOKUP() requires. (An anonymous person on Excel's UserVoice site showed me this.)



                        You must now use the range we just avoided, A1:E1, to get the column number directly. If you begin it with B1, you have to add a "1" to the result, so this is simpler to read and understand:



                        =MATCH(  VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )  , A1:E1 )


                        which returns "2" for the column (coincidentally, nothing more, the same as our input, but admit no confusion into your game!). So finally, you will put it all together as:



                        =VLOOKUP( HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE ) , A1:E5 , MATCH( VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE ) , A1:E1 ) , FALSE )


                        Use "FALSE" for it because you either have exact matches available, or something has gone BADLY wrong.



                        (If only the columns, or only the rows are amenable, you can still adapt here. You just have a harder time because only half of it is solved with this, but that can be enough, I have found. I've used it maybe 6-8 times since I learned the MATCH() idea to regain the row/column headers as Labels functionality and half of them only one was "ruly".)





                        share








                        New contributor




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























                          0












                          0








                          0







                          Since the labels are well-formed, which in the case of labels means, basically, they are ordered as if they had been sorted low-to-high by their first characters' character codes, one can take advantage of the last argument in VLOOKUP() and HLOOKUP(), taking the "approximate match" choice.



                          You do this to create the lookup value and the column to look in for a VLOOKUP() which will do the final work.



                          In the end, you have a simple VLOOKUP(). What to look up in it? Let's say your table shown is A1:E5 with its row labels in A2:A5 (DO NOT include that first row!) and its column labels being in B1:E1 (DO NOT include that first column!) and its actual data in B2:E5. If you include those first rows and columns (A1's), you will get the #N/A error. And let's say you handle obtaining the input values yourself, so however the "2, 19" material is created is however it is made available (I'll call it "Column to look in" and "Row to look in".) Then:



                          =HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE )


                          will return "18-20" which we will use directly as the lookup value, and



                          =VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )


                          will return "1-2" and here is where the "slight trick" comes in.



                          If we wrap that last function in a MATCH() function, it uses the "1-2" to find the column number to look in which the final VLOOKUP() requires. (An anonymous person on Excel's UserVoice site showed me this.)



                          You must now use the range we just avoided, A1:E1, to get the column number directly. If you begin it with B1, you have to add a "1" to the result, so this is simpler to read and understand:



                          =MATCH(  VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )  , A1:E1 )


                          which returns "2" for the column (coincidentally, nothing more, the same as our input, but admit no confusion into your game!). So finally, you will put it all together as:



                          =VLOOKUP( HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE ) , A1:E5 , MATCH( VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE ) , A1:E1 ) , FALSE )


                          Use "FALSE" for it because you either have exact matches available, or something has gone BADLY wrong.



                          (If only the columns, or only the rows are amenable, you can still adapt here. You just have a harder time because only half of it is solved with this, but that can be enough, I have found. I've used it maybe 6-8 times since I learned the MATCH() idea to regain the row/column headers as Labels functionality and half of them only one was "ruly".)





                          share








                          New contributor




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










                          Since the labels are well-formed, which in the case of labels means, basically, they are ordered as if they had been sorted low-to-high by their first characters' character codes, one can take advantage of the last argument in VLOOKUP() and HLOOKUP(), taking the "approximate match" choice.



                          You do this to create the lookup value and the column to look in for a VLOOKUP() which will do the final work.



                          In the end, you have a simple VLOOKUP(). What to look up in it? Let's say your table shown is A1:E5 with its row labels in A2:A5 (DO NOT include that first row!) and its column labels being in B1:E1 (DO NOT include that first column!) and its actual data in B2:E5. If you include those first rows and columns (A1's), you will get the #N/A error. And let's say you handle obtaining the input values yourself, so however the "2, 19" material is created is however it is made available (I'll call it "Column to look in" and "Row to look in".) Then:



                          =HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE )


                          will return "18-20" which we will use directly as the lookup value, and



                          =VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )


                          will return "1-2" and here is where the "slight trick" comes in.



                          If we wrap that last function in a MATCH() function, it uses the "1-2" to find the column number to look in which the final VLOOKUP() requires. (An anonymous person on Excel's UserVoice site showed me this.)



                          You must now use the range we just avoided, A1:E1, to get the column number directly. If you begin it with B1, you have to add a "1" to the result, so this is simpler to read and understand:



                          =MATCH(  VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE )  , A1:E1 )


                          which returns "2" for the column (coincidentally, nothing more, the same as our input, but admit no confusion into your game!). So finally, you will put it all together as:



                          =VLOOKUP( HLOOKUP( "Row to look in" , A1:A5 , 1, TRUE ) , A1:E5 , MATCH( VLOOKUP( "Column to look in" , A1:E1 , 1 , TRUE ) , A1:E1 ) , FALSE )


                          Use "FALSE" for it because you either have exact matches available, or something has gone BADLY wrong.



                          (If only the columns, or only the rows are amenable, you can still adapt here. You just have a harder time because only half of it is solved with this, but that can be enough, I have found. I've used it maybe 6-8 times since I learned the MATCH() idea to regain the row/column headers as Labels functionality and half of them only one was "ruly".)






                          share








                          New contributor




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








                          share


                          share






                          New contributor




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









                          answered 5 mins ago









                          RoyRoy

                          1




                          1




                          New contributor




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





                          New contributor





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






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






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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%2fsuperuser.com%2fquestions%2f1293852%2fhow-can-i-do-a-two-dimensional-lookup-where-the-column-and-row-headers-are-range%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

                              Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                              VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                              Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...