Find the group an item belongs to

abaker77

New Member
Joined
Oct 11, 2011
Messages
18
Office Version
  1. 365
I am looking for a non-VBA solution, i.e. an Excel formula, that can find the group to which an item belongs. Put another way, I need to find the contents of the 1st row in a given column.
An image of what this looks like is attached - there is a table of codes (items, if you will) and the column headers are the Groups.
The idea is to enter a code into cell C2, then find (or lookup) the corresponding group (1st cell) to which that code belongs. The formula for this would be in cell C3. So in my example, code594 is in GroupD, so the formula in C3 should return the result GroupD.
It is possible that the code entered in C2 may be duplicated in the table, but in this case, I would just expect the 1st column that has that code to be returned.
If there was a way to find the column # of the code entered in C2, then I guess you could find the contents of the 1st cell in the applicable column, i.e. Group, but I can't figure it out.
Thank you so much !
 

Attachments

  • find group.JPG
    find group.JPG
    133 KB · Views: 74

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Which version of Excel are you using?
Please update your account details to show this, as it affects which functions you can use.
 
Upvote 0
with Power Query
GroupAGroupBGroupCGroupDGroupEGroupFCodeGroup
code621code436code543code359code902code619code334GroupA
code334code709code703code459code334code614GroupE
code169code100code591code160code905code291
code476code557code223code749code717code851
code964code127code768code634code409code158
code931code487code623code594code477code586
code160code259code107code986code261code829

after changing Code refresh green table to see new Group(s)
Power Query:
let
    Code = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Matrix = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Matrix, {}, "Group", "Value"),
    Join = Table.NestedJoin(Code,{"Code"},Unpivot,{"Value"},"Table",JoinKind.FullOuter),
    Expand = Table.ExpandTableColumn(Join, "Table", {"Group"}, {"Group"}),
    Filter = Table.SelectRows(Expand, each [Code] <> null),
    TSC = Table.SelectColumns(Filter,{"Group"})
in
    TSC
 
Upvote 0
with Power Query

Code = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Matrix = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
Unpivot = Table.UnpivotOtherColumns(Matrix, {}, "Group", "Value"),
Join = Table.NestedJoin(Code,{"Code"},Unpivot,{"Value"},"Table",JoinKind.FullOuter),
Expand = Table.ExpandTableColumn(Join, "Table", {"Group"}, {"Group"}),
Filter = Table.SelectRows(Expand, each
Code:
 <> null),
    TSC = Table.SelectColumns(Filter,{"Group"})
in
    TSC
thank you for your Power Query solution but I really need to find a non-VBA solution. Ideally, I need a formula that can return the Group name.
Thanks for your time, anyway - I really appreciate it.
(I'm using Office 365, by the way.)
 
Upvote 0
No problem :)
Power Query is NOT a vba
update profile about excel version not a post
 
Upvote 0
Ok, how about
+Fluff v2.xlsm
ABCDEFGHI
1
2Code211
3Group 5
4
5Group 1Group 2Group 3Group 4Group 5Group 6Group 7Group 8
6Code382Code903Code344Code146Code101Code576Code859Code454
7Code701Code989Code814Code590Code746Code438Code423Code107
8Code522Code223Code317Code861Code211Code648Code471Code339
9Code837Code628Code448Code618Code234Code331Code986Code989
10Code828Code441Code128Code341Code196Code197Code401Code560
11
Main
Cell Formulas
RangeFormula
C3C3=INDEX(B5:I5,AGGREGATE(15,6,(COLUMN(B5:I5)-COLUMN(B5)+1)/(B6:I10=C2),1))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B6:I10Expression=B6=$C$2textNO
B6:I10Expression=COUNTIFS($B$6:$I$10,B6)>1textNO


Please don't forget to update your account details & then scroll down & click save.
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
YES, extremely brilliant - a great solution.
One question - what is the recommendation if (in the example shown) there are duplicate codes?
This formula appears to return the 'last' group in which the duplicate item appears.
 
Upvote 0
It such a year from last help. Not sure the helper is online or not, but try a little twist:

Put this in C3 then drag accross to D3,E3 as far as possible:

Code:
=IFERROR(INDEX($B$5:$I$5,AGGREGATE(15,6,(COLUMN($B$5:$I$5)-COLUMN($B$5)+1)/($B$6:$I$10=$C$2),COLUMNS($A:A))),"")
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top