+ Reply to Thread
Results 1 to 10 of 10

Lookup value, return column header

  1. #1
    Registered User
    Join Date
    07-20-2011
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    7

    Lookup value, return column header

    My title would have been a paragraph if I truly described what I needed, so sorry if my issue isn't totally defined by the title. Here is my issue:

    I have a worksheet (sheet2) with rows that contain ID #'s in column A and one of the following values {0,33,50,100} in each cell from column G to AG. I want to focus on the cells with "0"s in them. Here is what I need:

    In sheet1, A1, I want to type a Student ID. I then want to enter a formula in B1 that looksup the ID in Sheet2 and returns the column header of the 1st "0" it finds

    Next, in Sheet1, B2, I want to enter a formula that will lookup the A1's ID in sheet2 and return the column header of the 2nd "0" it finds.

    I want to end up with values in B1 to B10 in sheet1 that are the column headers of the first 10 zeros in each row in sheet2 based on the ID that I type in A1 in Sheet1.

    A lot to ask, I know, but you all are brilliant so I hope you can find a solution.

    Thanks,

    John

  2. #2
    Valued Forum Contributor
    Join Date
    09-07-2006
    Posts
    520

    Re: Lookup value, return column header

    Here's a non-array formulas set-up to deliver it ...

    In Sheet2 (your source data),
    This sets up the criteria range
    Put in AI1: =IF(G1="","",G1)
    Copy across by 27 cols to BI1 to repeat the col headers in G1:AG1
    Put in AI2: =IF(G2="","",IF(G2=0,COLUMNS($A:A),""))
    Copy across to BI2, fill down as far as required

    Then in Sheet1,
    The student ID input will be made in A1 (as you posted)
    Put in B1:
    =IF(ROWS($1:1)>COUNT(OFFSET(Sheet2!$AI$1:$BI$1,MATCH(A$1,Sheet2!$A:$A,0)-1,)),"",INDEX(Sheet2!$AI$1:$BI$1,SMALL(OFFSET(Sheet2!$AI$1:$BI$1,MATCH(A$1,Sheet2!$A:$A,0)-1,),ROWS($1:1))))
    Copy down as far as required to extract the desired results

    The above allows for easy flexibility and extension - Col B can be simply copied and pasted into adjoining cols for simultaneous extraction of results for other student IDs. Eg col B pasted into col E will return the results for the student ID input in D1. Repeat the paste into col H to return results for the student ID input into G1. And so on, as you may desire.

    Also, the criteria formulae takes care of the subtleness of source blank cells being evaluated as zeros by formulas, it makes blank cells distinct from cells with zeros.

    ------------
    Success?, Celebrate it, click the little star at the bottom left of my response
    Last edited by Max, Singapore; 08-25-2012 at 01:34 PM.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Lookup value, return column header

    try like this just a simple index match with a single helper row
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

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

    Re: Lookup value, return column header

    Pl see the attached file.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-20-2011
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Lookup value, return column header

    Perhaps I made a mistake creating arbitrary cell references. In Sheet 1, my student ID is in O2, not A1. I need the Column Headers to be placed in the following cells: O13, O34, O55, O76, O97, O118, O139, O160, O181, O202. I tried Martin's and Kvsrinivasamurthy's but neither worked.

    Any thoughts?

  6. #6
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Lookup value, return column header

    You can post/attach a sample file of your work for them to give the "exact formulas". include the expected out come..
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  7. #7
    Registered User
    Join Date
    07-20-2011
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Lookup value, return column header

    I hope I attached it correctly. I made notes in the rows of Sheet 1
    Attached Files Attached Files

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

    Re: Lookup value, return column header

    PL see the attached file.
    If it is OK mark thread solved.
    Thanks.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-20-2011
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Lookup value, return column header

    Some of the entries are incorrect. Here are headers that are zeros for 196705:

    MA.9-10.2.2.PO 2
    MA.9-10.2.3.PO 2
    MA.9-10.2.3.PO 3
    MA.9-10.3.2.PO 2
    MA.9-10.3.3.PO 11
    MA.9-10.3.3.PO 13
    MA.9-10.3.3.PO 14
    MA.9-10.3.3.PO 3
    MA.9-10.3.3.PO 5
    MA.9-10.3.3.PO 6
    MA.9-10.3.4.PO 1
    MA.9-10.4.2.PO 4
    MA.9-10.4.3.PO 5
    MA.9-10.4.3.PO 8

    Some have been skipped over, and some that ARE on Sheet 1 shouldn't be.

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Lookup value, return column header

    ok try this version ps the other version works but you didnt say you were placing the formulas 22 rows apart!
    Attached Files Attached Files
    Last edited by martindwilson; 08-28-2012 at 10:52 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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