How do I get Excel to return the column header of text that appears in an array?

PCnetMD

New Member
Joined
Oct 14, 2018
Messages
1
I need to determine which column a specific item is located.

[TABLE="width: 256"]
<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl66, width: 64"]1[/TD]
[TD="class: xl66, width: 64"]2[/TD]
[TD="class: xl66, width: 64"]3[/TD]
[TD="class: xl66, width: 64"]4[/TD]
[/TR]
[TR]
[TD="class: xl67"]water[/TD]
[TD="class: xl67"]lettuce[/TD]
[TD="class: xl67"]chicken[/TD]
[TD="class: xl67"]ice cream[/TD]
[/TR]
[TR]
[TD="class: xl67"]cola[/TD]
[TD="class: xl67"]tomato[/TD]
[TD="class: xl67"]beef[/TD]
[TD="class: xl67"]cake[/TD]
[/TR]
[TR]
[TD="class: xl67"]juice[/TD]
[TD="class: xl67"]cucumber[/TD]
[TD="class: xl67"]pork[/TD]
[TD="class: xl67"]pie[/TD]
[/TR]
[TR]
[TD="class: xl67"]coffee[/TD]
[TD="class: xl67"]okra[/TD]
[TD="class: xl67"]lamb[/TD]
[TD="class: xl67"]brownie[/TD]
[/TR]
[TR]
[TD="class: xl67"]tea[/TD]
[TD="class: xl67"]carrot[/TD]
[TD="class: xl67"]shrimp[/TD]
[TD="class: xl67"]cookie[/TD]
[/TR]
[TR]
[TD="class: xl67"]milk[/TD]
[TD="class: xl67"]onion[/TD]
[TD="class: xl67"]fish[/TD]
[TD="class: xl67"]candy[/TD]
[/TR]
</tbody>[/TABLE]

How do I get Excel to return the column header of text that appears in the above array? Everything I have found only works for number(values).

Thank you,
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I need to determine which column a specific item is located.

[TABLE="width: 256"]
<tbody>[TR]
[TD="class: xl66, width: 64"]1[/TD]
[TD="class: xl66, width: 64"]2[/TD]
[TD="class: xl66, width: 64"]3[/TD]
[TD="class: xl66, width: 64"]4[/TD]
[/TR]
[TR]
[TD="class: xl67"]water[/TD]
[TD="class: xl67"]lettuce[/TD]
[TD="class: xl67"]chicken[/TD]
[TD="class: xl67"]ice cream[/TD]
[/TR]
[TR]
[TD="class: xl67"]cola[/TD]
[TD="class: xl67"]tomato[/TD]
[TD="class: xl67"]beef[/TD]
[TD="class: xl67"]cake[/TD]
[/TR]
[TR]
[TD="class: xl67"]juice[/TD]
[TD="class: xl67"]cucumber[/TD]
[TD="class: xl67"]pork[/TD]
[TD="class: xl67"]pie[/TD]
[/TR]
[TR]
[TD="class: xl67"]coffee[/TD]
[TD="class: xl67"]okra[/TD]
[TD="class: xl67"]lamb[/TD]
[TD="class: xl67"]brownie[/TD]
[/TR]
[TR]
[TD="class: xl67"]tea[/TD]
[TD="class: xl67"]carrot[/TD]
[TD="class: xl67"]shrimp[/TD]
[TD="class: xl67"]cookie[/TD]
[/TR]
[TR]
[TD="class: xl67"]milk[/TD]
[TD="class: xl67"]onion[/TD]
[TD="class: xl67"]fish[/TD]
[TD="class: xl67"]candy[/TD]
[/TR]
</tbody>[/TABLE]

How do I get Excel to return the column header of text that appears in the above array? Everything I have found only works for number(values).

Thank you,

=INDEX(A1:D1,MAX((A2:D7="pork")*COLUMN(A:D)))
Ctrl shift enter for the array formula.
 
Upvote 0
Assume your data is arranged as follows:

Data Range
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[TD]
F
[/TD]
[TD]
G
[/TD]
[TD]
H
[/TD]
[TD]
I
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]
water​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
1​
[/TD]
[TD]
2​
[/TD]
[TD]
3​
[/TD]
[TD]
4​
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
cola​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
water​
[/TD]
[TD]
lettuce​
[/TD]
[TD]
chicken​
[/TD]
[TD]
ice cream​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
juice​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
cola​
[/TD]
[TD]
tomato​
[/TD]
[TD]
beef​
[/TD]
[TD]
cake​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
coffee​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
juice​
[/TD]
[TD]
cucumber​
[/TD]
[TD]
pork​
[/TD]
[TD]
pie​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
tea​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
coffee​
[/TD]
[TD]
okra​
[/TD]
[TD]
lamb​
[/TD]
[TD]
brownie​
[/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]
milk​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
tea​
[/TD]
[TD]
carrot​
[/TD]
[TD]
shrimp​
[/TD]
[TD]
cookie​
[/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]
lettuce​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
milk​
[/TD]
[TD]
onion​
[/TD]
[TD]
fish​
[/TD]
[TD]
candy​
[/TD]
[/TR]
[TR]
[TD]
8
[/TD]
[TD]
tomato​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
9
[/TD]
[TD]
cucumber​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
10
[/TD]
[TD]
okra​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
11
[/TD]
[TD]
carrot​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
12
[/TD]
[TD]
onion​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
13
[/TD]
[TD]
chicken​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
14
[/TD]
[TD]
beef​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
15
[/TD]
[TD]
pork​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
16
[/TD]
[TD]
lamb​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
17
[/TD]
[TD]
shrimp​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
18
[/TD]
[TD]
fish​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
19
[/TD]
[TD]
ice cream​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
20
[/TD]
[TD]
cake​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
21
[/TD]
[TD]
pie​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
22
[/TD]
[TD]
brownie​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
23
[/TD]
[TD]
cookie​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
24
[/TD]
[TD]
candy​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

then the following VBA will do what you need

Code:
Option Explicit


Sub foo()
    Dim i As Long, c As Range
    Dim rng As Range, x As Long
    Set rng = Range("F2:I7")
    Dim lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        For Each c In rng
            If Range("A" & i) = c Then
                x = c.Column
                Range("B" & i) = Cells(1, x)
            End If
        Next c
    Next i
End Sub
 
Last edited:
Upvote 0
Use this formula

=SUMPRODUCT((a1:d6="tea")*(COLUMN(a1:d6)))

you will get answer as 1
 
Upvote 0
Does a value like okra repeat? If it does, do you need all of the corresponding headers? By the way, is the set of 1, 2, 3, and 4 the header set?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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