Display Column First Row Header when Matched

Posted on 2014-07-18
Last Modified: 2014-08-04
Hello Experts,
I need an Excel 2010 formula that will display the first header row when a match is found within an array based on a value:
Value        Result from first row
Oakland = City
Bob = Name

ID   Name  City
1      Joe      Houston
2      Bob     New York
3      Jill        Oakland
Question by:ShadowIT
    LVL 27

    Expert Comment

    by:Glenn Ray
    I'm going to re-state your question; please confirm that this is correct.

    A table exists with data.  A user enters an arbitrary value.  A formula is desired that will identify the type of information as listed in a header row of the table.

    For example, if a table contains three columns of data, with the header row containing:
    A1:  "ID"
    B1: "Name"
    C1: "City"

    with values below being:
    A2: 1
    B2: "Joe"
    C2: "Houston"
    A3: 2
    B3: "Bob"
    C3: "New York"
    A4: 3
    B4: "Jill"
    C4: "Oakland"

    and the user enters the value "Oakland" in a cell, the formula will return the value "City"
    Likewise, if the user enters the value "Bob", the formula will return the value "Name"

    1) What if a value occurs in more than one column?  For example, "Austin" could be a person's name or the name of a city.
    2) What do you want to see if there is no match?


    Author Comment

    Yes, that's right

    1) What if a value occurs in more than one column?  For example, "Austin" could be a person's name or the name of a city.

    Just the first it encounters it fine

     2) What do you want to see if there is no match?

    N/ match found...doesn't really matter to me

    Author Comment

    this is close but only works if I specify a specific row and I need this to work for an array:

    =INDEX($A$1:$E$1,1, MATCH(1,$A2:$E2,0))
    LVL 27

    Expert Comment

    by:Glenn Ray

    I'm close to a solution, but am trying to avoid either nested IF statements (an approach seen here in EE) or a helper row.  Both cases work (I have a workbook with both types), but am trying to see if I can use an array function instead.

    LVL 27

    Accepted Solution


    Sorry for the long delay in getting a solution to you, but I did figure it out.  Assuming the value to search for is in G2, the formula to return the header row lable (field name) would be:
    =IFERROR(INDEX($A$1:$E$1,1,SUMPRODUCT(($A$1:$E$20=$G$2)*(COLUMN($A$1:$E$20)))/COUNTIF($A$1:$E$20,$G$2)),"Not Found")

    This is only searching down to row 20; you'd want to change that value accordingly.  Example workbook attached.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
    This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now