MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Nov 28th, 2008, 08:12 PM   #1
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 642
Default Return Column Headers Based On LARGE function

Return Column Headers Based On LARGE function

Dear Most Amazing Excelers In The World,

In the cell range A1:F3, I have this data:

Day EP US IL DK Mex
Day 100 4 15 13 10 9
Day 101 3 5 11 5 9

And I would like to create a formula that will return the column headers based on the largeness of the values in each row of numbers (large 1, large 2, large 3, large 4, large 5). The values I would like the formula to return are here:

Day Large 1 Large 2 Large 3 Large 4 Large 5
Day 100 US IL DK Mex EP
Day 101 IL Mex US DK EP

This is because for the:
First row, US = Large 1 = 15, IL = Large 2 = 13, DK = Large 3 = 10, Mex = Large 4 = 9, and EP = Large 5 = 4
Second row IL = Large 1 = 11, Mex = Large 2 = 9, US = 1st Large 3 in row = 5, DK = 2nd Large 3 in row = 5, and EP = Large 5 = 3

I have created this formula:

{=INDEX($B$1:$F$1,,SMALL(IF($B2:$F2=LARGE($B2:$F2,COLUMNS($I11:I11)),COLUMN($B$1:$F$1)-COLUMN($B$1)+1),COUNTIF($B2:$F2,LARGE($B2:$F2,COLUMNS($I11:I11)))))}

But I get this data returned:

Day Large 1 Large 2 Large 3 Large 4 Large 5
Day 100 US IL DK Mex EP
Day 101 IL Mex DK DK EP

I cannot seem to get my formula to deal with duplicates. In the second row I get 2 DKs instead of US and then DK.

Can any of you Formula Excel Masters help me?
__________________
Sincerely, Mike Girvin
mgirvin is offline   Reply With Quote
Old Nov 28th, 2008, 08:52 PM   #2
Domenic
MrExcel MVP
 
Join Date: Mar 2004
Location: Canada
Posts: 9,884
Default Re: Return Column Headers Based On LARGE function

Try...

I2, confirmed with CONTROL+SHIFT+ENTER, copied across and down:

=INDEX($B$1:$F$1,MATCH(SMALL(RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,COLUMNS($I2:I2)),RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,0))

Hope this helps!
Domenic is offline   Reply With Quote
Old Nov 28th, 2008, 09:38 PM   #3
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 642
Default Re: Return Column Headers Based On LARGE function

Dear Domenic,

Wow! Once again, your Excel Magic is amazing! It helps a great deal, not only that but I get to learn a few new Excel concepts such as:

Using the RANK to get an array of ranked vales
and
Adding just a little bit extra to break the ties

I have this question though:

Why are you putting a row number into the index function when the values are sitting in columns?

I tried your formula:

=INDEX($B$1:$F$1,MATCH(SMALL(RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,COLUMNS($I2:I2)),RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,0))

where the "MATCH(SMALL(RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,COLUMNS($I2:I2)),RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,0)" puts a row number into the INDEX.

Then I tried it this way:

=INDEX($B$1:$F$1,,MATCH(SMALL(RANK($B4:$F4,$B4:$F4)+COLUMN($B4:$F4)/1000,COLUMNS($I4:K4)),RANK($B4:$F4,$B4:$F4)+COLUMN($B4:$F4)/1000,0))

where the "MATCH(SMALL(RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,COLUMNS($I2:I2)),RANK($B2:$F2,$B2:$F2)+COLUMN($B2:$F2)/1000,0)" puts a column number into the INDEX.

It worked both ways. Does this mean that when the array in the INDEX is in columns, you can give the INDEX a row number or a column number and it will work?

Thanks so much Domenic!!!!!
__________________
Sincerely, Mike Girvin
mgirvin is offline   Reply With Quote
Old Nov 28th, 2008, 10:09 PM   #4
Domenic
MrExcel MVP
 
Join Date: Mar 2004
Location: Canada
Posts: 9,884
Default Re: Return Column Headers Based On LARGE function

Quote:
Originally Posted by mgirvin View Post
...It worked both ways. Does this mean that when the array in the INDEX is in columns, you can give the INDEX a row number or a column number and it will work?
Yes, that's right. If the indexed array, in this case B1:F1, contains only one row or column, the corresponding row_num or column_num argument is optional.

Quote:
Thanks so much Domenic!!!!!
You're very welcome!
Domenic is offline   Reply With Quote
Old Nov 28th, 2008, 10:22 PM   #5
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 642
Default Re: Return Column Headers Based On LARGE function

Dear Domenic,

Now I can add that to my list of things learned from your elegant formula.

Thanks for the formula and the new Excel concepts!
__________________
Sincerely, Mike Girvin
mgirvin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 05:16 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2010 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes