+ Reply to Thread
Results 1 to 13 of 13

Return the column header for every value 'x' along each row in table

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    5

    Return the column header for every value 'x' along each row in table

    Hi,

    The formula I am looking to write is;
    "For every instance of "RULE!" in this row, return every corresponding value from the table's header row".

    I have searched through the forum and although there are similar queries using INDEX and MATCH with column data, I have been unable to convert those formulae to refer to ROW data.

    I have attached a workbook for reference, (this is a small subset of a very large workbook of rules that applies to investment portfolios).
    I would like to write the formulae down column B (coloured orange), referring to the data in C2:G8.

    The formula would 'look' along the relevant row and return the header from each column that contains the word "RULE!"
    The formula once written should return the values I have entered manually in column B.
    The formula only 'counts' the word "Rule!" and ignores any other text (so the values "Active" and "N/A" are ignored)

    Thank you in advance for your help and for hosting a great forum!
    Cheers
    pcassidy
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Return the column header for every value 'x' along each row in table

    Hi pcassidy and welcome to the forum

    Im sure some-one will come up with a far more eligant solution for you, but until they do, try this brute force, copied down...

    =IF(C2="Rule!",C$1&",","")&IF(D2="Rule!",C$1&",","")&IF(E2="Rule!",C$1&",","")&IF(F2="Rule!",C$1&",","")&IF(G2="Rule!",C$1&",","")
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    10-04-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Return the column header for every value 'x' along each row in table

    Thank you very much for your suggestion FDibbins.

    That would definitely work on the small table that I posted, but the problem is that the actual table of rules I want to apply this to is alot larger.
    So while in the posted example spreadsheet there are only 5 columns with headers, in the full database I have over 100 headers - which would require a gigantic nested IF.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Return the column header for every value 'x' along each row in table

    Yup, I kinda figured you would say that lol
    Last edited by FDibbins; 01-21-2013 at 01:07 AM.

  5. #5
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Return the column header for every value 'x' along each row in table

    See if you can use this : pcassidy.Rule Set Query.sol1.xlsx

    I used a helper sheet (which could be hidden if desired) to hold the interim results

    The named range Headers is dynamic to about 200 headers

    Hopefully As FDibbins says, someone can come up with a more elegant solution....but this will work
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return the column header for every value 'x' along each row in table

    If you want multiple results all in a single cell then you're going to need some form of VBA to do this.

    Ideally, you'd want all of the processing to be done with the VBA code. I'm not much of a programmer but if no one else comes up with a 100% code solution I have a solution that uses both a VBA function combined with worksheet functions.

    I'll follow the thread to see if anyone else chimes in.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Registered User
    Join Date
    10-04-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Return the column header for every value 'x' along each row in table

    Hi dredwolf,

    Thank you very much for your efforts.
    I am just testing out your suggestion on my full spreadsheet - and while I have no idea how those formulae work or how the helper sheet works, it seems to be doing the job!

    I will get back to you and the forum shortly.
    Cheers!

  8. #8
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Return the column header for every value 'x' along each row in table

    Thanks

    I hope they work out okay for you !

  9. #9
    Registered User
    Join Date
    10-04-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Return the column header for every value 'x' along each row in table

    Hi dredwolf,

    I tested this out on the full worksheet and it is great! You have quite literally saved me hours of frustration!
    I have over 250 rows of rules and over 100 portfolio columns to apply this to but somehow with that magic helper sheet it all works a charm.

    Thank you once again!

  10. #10
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Return the column header for every value 'x' along each row in table

    You are very welcome

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return the column header for every value 'x' along each row in table

    Here's that VBA UDF method...

    Copy the code below and paste it into a general module:

    Please Login or Register  to view this content.
    Then, enter this array formula in B2 and copy down as needed:

    =SUBSTITUTE(TRIM(aconcat(IF(C2:G2="Rule!"," "&C$1:G$1,"")))," ",", ")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  12. #12
    Registered User
    Join Date
    10-04-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Return the column header for every value 'x' along each row in table

    Hi Tony,

    Thank you as well for your suggestion.
    Again, I have no idea how this works, but it does, it works perfectly! It is a very tidy and most excellent solution!

    I really appreciate your response and efforts to solve my problem.
    Cheers!

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return the column header for every value 'x' along each row in table

    You're welcome. Thanks for the feedback!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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