+ Reply to Thread
Results 1 to 15 of 15

Lookup in two-dimensional array, return header value

  1. #1
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Lookup in two-dimensional array, return header value

    Hi,

    Is it possible to write a lookup function that searches a two-dimension array (rows and columns), and returns the header value for the column that the lookup was found in?
    Everything I've found online references a situation where you want to return from a vertical array, but in my case, the return would be a value in a horizontal array (header row).
    See attached for sample file.
    Thank you

    ExcelForum - xtinct2 - 2023.06.15.xlsx

  2. #2
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: Lookup in two-dimensional array, return header value

    Clean all expected data.

    K5
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by windknife; 06-15-2023 at 04:42 AM.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Lookup in two-dimensional array, return header value

    @Windknife - pleae explain INDEX($4:$4 ... for my edification. Thanks.
    Ali


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

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Lookup in two-dimensional array, return header value

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


    Courtesy of: https://www.xelplus.com/complex-look...ex-sumproduct/
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Lookup in two-dimensional array, return header value

    Put in K5 and copied down:

    =IFERROR(INDEX($B$4:$H$4,SUMPRODUCT(($B$5:$H$16=J5)*COLUMN($B$5:$H$16))-COLUMN($B$4:$H$4)+1),"")
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: Lookup in two-dimensional array, return header value

    @Ali It don't need to use $4:$4, 4:4 is enought. I am used to adding $ in elder excel version ^_^

  7. #7
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,427

    Re: Lookup in two-dimensional array, return header value

    Cell K5 formula

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

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

    Re: Lookup in two-dimensional array, return header value

    Quote Originally Posted by windknife View Post
    @Ali It don't need to use $4:$4, 4:4 is enought. I am used to adding $ in elder excel version ^_^
    That doesn't answer the querstion. What does it do? How does it work?

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Lookup in two-dimensional array, return header value

    @Ali, $4:$4 and 4:4 is the entire row 4. And later, the COLUMN function will select the correct cell in that row.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Lookup in two-dimensional array, return header value

    @Ali: have a look at the link in post #4 for the basics of the approach.

  11. #11
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: Lookup in two-dimensional array, return header value

    Thanks @Hans and @TMS for explaining my formula.

    About my formula, first I use SUMPRODUCT((B5:H16=x)*(COLUMN(B5:H5))) to find the match column.Then, I use Index(4:4 to find the header. Of course, Index(B4:H4 is also okay.

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

    Re: Lookup in two-dimensional array, return header value

    Thanks, all - the penny has now dropped (mainly thanks to Hans). I was missing the b******g obvious!!!

  13. #13
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Lookup in two-dimensional array, return header value

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

  14. #14
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Lookup in two-dimensional array, return header value

    Try. In K5
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  15. #15
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Lookup in two-dimensional array, return header value

    If there is repetition of same number below formula works. PL see file.
    In K5
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to do an array lookup, and return the header if the column.
    By markmarhon in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-12-2019, 03:35 AM
  2. [SOLVED] Lookup value in 2-dimensional array
    By LadyS in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 05-18-2017, 02:35 PM
  3. Two dimensional lookup return column header
    By stephboucher in forum Excel General
    Replies: 3
    Last Post: 09-24-2016, 02:24 PM
  4. Replies: 5
    Last Post: 12-24-2011, 12:16 PM
  5. lookup value within a two dimensional array
    By tanababa in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-13-2010, 07:36 AM
  6. [SOLVED] Lookup Value in Range/Array and Return Column Header Value
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2010, 08:17 AM
  7. Replies: 3
    Last Post: 06-16-2006, 02:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1