+ Reply to Thread
Results 1 to 13 of 13

Comparing 3+ columns and need to return clumn header of lowest (or column headers)

  1. #1
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Hi,

    I have a table of data with 3 columns of data I want to compare (could be more columns though) and I want to return the header of the column that has the lowest value. If two or more columns are of equal size (and are the joint lowest) then I'd like the column headers returned together.

    I've managed to create a formula to return the column header (c2,d2 or e2) with the lowest value:- =CHOOSE(MATCH(SMALL(C4:E4,1),C4:E4,0),$C$2,$D$2,$E$2), however I haven't been table to take it that one step further whereby it would return C2 & D2 in the same cell IF both matched and were the smallest.

    EXCEL SCREENSHOT.JPG

    Is it possible to do this?

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,081

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    the cleanest way to do this is with a UDF:

    Please Login or Register  to view this content.
    How to install your new code
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Press Alt+F11 to open the Visual Basic Editor
    Choose Insert > Module
    Edit > Paste the macro into the module that appeared
    Close the VBEditor
    Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


    Then use this array formula:

    =ConcatAll(IF(D2:F2=MIN(D2:F2),$D$1:$F$1,""),", ")

    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: Lá fhéile Pádraig sona dhaoibh

  3. #3
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Glenn,

    Really appreciate the response - is there anyway to do this without the VBA?

    Thanks,

    Richard.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,081

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Define the maximum number of columns that could be involved....

  5. #5
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    If I say for now "3" - I can then adjust as required.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,081

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Up to a point.... If there are many ore than 3... any other solution will get very messy. I will provide a solution for 3, but I would like an answer to my Q...

  7. #7
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Sorry, not trying to be evasive - really appreciate the help. I can't see it being above 5 or 6.

    Essentially its a quote comparison of suppliers - normally we'd get a price from a current supplier and then 2 others (hence the 3), but it could be more

    Is 5 or 6 too many?

  8. #8
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    really appreciate the quick responses by the way

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,081

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Ok. Thats do-able. Look up in a short time...

  10. #10
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    thank you, will do.

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,081

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Option 1 was VBA.

    Option 2 delivers results in separate cells (again an array formula, copied across and down):
    =IFERROR(INDEX($F$1:$H$1,SMALL(IF($F2:$H2=MIN($F2:$H2),COLUMN($F2:$H2)-COLUMN($F2)+1),COLUMNS($I:I))),"")

    Option 3 delivers results in a single celll (again, an array formula copied down: set for up to 3 minimum values):
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    see sheet for context.

    Obviously, if you go for one of the formula versions, save as .xlsx,rather than .xlsm
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    06-28-2005
    Posts
    48

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    Brillliant - thank you!

    All 3 solutions very useful.

    Really appreciate your efforts with this, i'd never have got there on my own.

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,081

    Re: Comparing 3+ columns and need to return clumn header of lowest (or column headers)

    You're welcome and thanks for the rep.

+ 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. [SOLVED] Return Column Header for First and Last Columns to Contain a Value
    By winkee223 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-29-2017, 10:09 AM
  2. [SOLVED] Comparing two columns and if there is a match then return values from a different column
    By skywalkertinks in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-26-2017, 07:18 AM
  3. Replies: 5
    Last Post: 02-13-2014, 05:37 PM
  4. [SOLVED] Compare dates across columns and return column header
    By huy_le in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-29-2013, 07:07 PM
  5. Finding the lowest 2 values across two rows, return row headers
    By ronanmagee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-04-2013, 06:08 AM
  6. Search for value in multiple columns, Return Column Headers
    By Zach51215 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2013, 06:49 AM
  7. [SOLVED] Return column header by comparing multiple row values conditions
    By aschom in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-06-2012, 08:52 PM

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