SOLVED
Home

Finding the column name for a value in a table

%3CLINGO-SUB%20id%3D%22lingo-sub-288305%22%20slang%3D%22en-US%22%3EFinding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288305%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%203x3%20table%20with%20a%20header%20and%20two%20data%20rows%20as%20below.%3CBR%20%2F%3E%3CBR%20%2F%3EA1%3DFirst%2C%20B1%3DSecond%2C%20C1%3DThird%3CBR%20%2F%3EA2%3D1%2C%20B2%3D2%2C%20C2%3D3%3CBR%20%2F%3EA3%3D4%2C%20B3%3D5%2C%20C3%3D6%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20cell%20D1%20I'd%20like%20to%20enter%20a%20search%20criteria.%20For%20example%205.%3CBR%20%2F%3EThen%20in%20E1%20I'd%20like%20to%20output%20the%20name%20of%20the%20header%20for%20that%20column.%20In%20this%20case%20Second.%3CBR%20%2F%3E%3CBR%20%2F%3EFollowing%20the%20logic%20this%20should%20be%20the%20result%20in%20E1%20when%20entering%20each%20number%20in%20D1.%3CBR%20%2F%3E%3CBR%20%2F%3E1%20%3D%20First%3CBR%20%2F%3E2%20%3D%20Second%3CBR%20%2F%3E3%20%3D%20Third%3CBR%20%2F%3E4%20%3D%20First%3CBR%20%2F%3E5%3D%20Second%3CBR%20%2F%3E6%20%3D%20Third%3CBR%20%2F%3E%3CBR%20%2F%3EI've%20tried%20Index%2C%20Match%20and%20Vlookup%20without%20success.%20How%20can%20you%20solve%20this%3F%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-288305%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288363%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288363%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20are%20welcome%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288360%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288360%22%20slang%3D%22en-US%22%3E%3CP%3EWorks%20great.%20Thanks%20again%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288359%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288359%22%20slang%3D%22en-US%22%3E%3CP%3EPeter%2C%20LEFT%20returns%20text%2C%20wrap%20it%20with%20VALUE%20to%20receive%20number%3C%2FP%3E%0A%3CPRE%3E%3DOFFSET(%24A%241%2C0%2CSUMPRODUCT((%24A%242%3A%24C%2415%3DVALUE(LEFT(%24E%242%2C2)))*COLUMN(%24A%242%3A%24C%2415))-1)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288339%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288339%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%2C%3CBR%20%2F%3E%3CBR%20%2F%3EThat%20works%20like%20a%20charm%20%3A)Let's%20say%20these%20numbers%20were%20part%20of%20a%20zip%20code.%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20in%20E1%20I%20would%20enter%2038000.%20Instead%20of%20the%20part%3A%20%24A%242%3A%24C%2415%3D%24E%241%3CBR%20%2F%3EI'd%20like%3A%20%24A%242%3A%24C%2415%3DLEFT(%24E%241%3B2)%3CBR%20%2F%3E%3CBR%20%2F%3EBut%20I%20get%20a%20%23REF!%20error.%20What%20can%20be%20wrong%20in%20this%20case%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288327%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288327%22%20slang%3D%22en-US%22%3E%3CP%3EIdea%20is%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fexceljet.net%2Fformula%2Fget-location-of-value-in-2d-array%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fexceljet.net%2Fformula%2Fget-location-of-value-in-2d-array%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20740px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F60163i4D6F560C172ED84C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288317%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288317%22%20slang%3D%22en-US%22%3E%3CP%3EThat%20helps%2C%20thanks%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20if%20I%20want%20to%20expand%20the%20table%20with%20more%20columns%20and%20rows%3F%20Is%20it%20possible%20to%20make%20the%20formula%20more%20dynamic%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-288309%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20the%20column%20name%20for%20a%20value%20in%20a%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-288309%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Peter%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20need%20to%20the%20Index%20%26amp%3B%20Match%20combination%20to%20solve%20this!%3C%2FP%3E%3CP%3EBut%20you%20need%20to%20nest%20another%20combination%20because%20you%20want%20to%20search%20the%20value%20in%20cell%20E1%20in%20two%20rows!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20formula%20looks%20like%20this%3A%3C%2FP%3E%3CPRE%3E%3DIFERROR(INDEX(A1%3AC3%2C%2CMATCH(D1%2CA2%3AC2%2C0))%2CINDEX(A1%3AC3%2C%2CMATCH(D1%2CA3%3AC3%2C0)))%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F60161iA38AD283E59C0888%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22INDEX%20%26amp%3B%20MATCH%20Combinations.png%22%20title%3D%22INDEX%20%26amp%3B%20MATCH%20Combinations.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20helps%3C%2FP%3E%3C%2FLINGO-BODY%3E
Peter Johansson
Occasional Contributor

I have a 3x3 table with a header and two data rows as below.

A1=First, B1=Second, C1=Third
A2=1, B2=2, C2=3
A3=4, B3=5, C3=6

In cell D1 I'd like to enter a search criteria. For example 5.
Then in E1 I'd like to output the name of the header for that column. In this case Second.

Following the logic this should be the result in E1 when entering each number in D1.

1 = First
2 = Second
3 = Third
4 = First
5= Second
6 = Third

I've tried Index, Match and Vlookup without success. How can you solve this? :)

7 Replies

Hi Peter,

 

You need to the Index & Match combination to solve this!

But you need to nest another combination because you want to search the value in cell E1 in two rows!

 

The formula looks like this:

=IFERROR(INDEX(A1:C3,,MATCH(D1,A2:C2,0)),INDEX(A1:C3,,MATCH(D1,A3:C3,0)))

 INDEX & MATCH Combinations.png

 

 

Hope that helps

That helps, thanks :)

 

What if I want to expand the table with more columns and rows? Is it possible to make the formula more dynamic?

Thanks,

That works like a charm :) Let's say these numbers were part of a zip code.

So in E1 I would enter 38000. Instead of the part: $A$2:$C$15=$E$1
I'd like: $A$2:$C$15=LEFT($E$1;2)

But I get a #REF! error. What can be wrong in this case?

Peter, LEFT returns text, wrap it with VALUE to receive number

=OFFSET($A$1,0,SUMPRODUCT(($A$2:$C$15=VALUE(LEFT($E$2,2)))*COLUMN($A$2:$C$15))-1)

 

Works great. Thanks again :)

You are welcome

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies