## Match a criterion and extract multiple corresponding table headers

*Article last updated on July 02, 2012*

example

row header ---> a b c d e

data 1 1 2 2 2

2 1 1

1 1 1 2

so how to find out which all headers appear agst 1 or 2o 3 in each row

### Answer:

**Array formula in cell B7:**

### How to create an array formula

- Copy array formula
- Select cell B7
- Paste formula in formula bar
- Press and hold Ctrl + Shift
- Press Enter

### How to copy array formula

- Select cell B7
- Copy cell (not formula)
- Select cell range C7:F7
- Paste (Ctrl +v)

### Explaining array formula in cell B7

**Step 1 - Filter column numbers**

IF($A7=$A$2:$E$4, COLUMN($A$2:$E$4), "")

becomes

IF("1"={1, 1, 2, 2, 2;2, 1, 1, 0, 0;1, 1, 1, 2, 0}, {1, 2, 3, 4, 5}, "")

and returns

{1, 2, "", "", "";"", 2, 3, "", "";1, 2, 3, "", ""}

**Step 2 - Calculate the frequencies of the numbers in the array**

FREQUENCY(IF($A7=$A$2:$E$4, COLUMN($A$2:$E$4), ""), COLUMN($A$2:$E$4))

becomes

FREQUENCY({1, 2, "", "", "";"", 2, 3, "", "";1, 2, 3, "", ""}, {1, 2, 3, 4, 5})

and returns

{2;3;2;0;0;0}

**Step 3 - Extract unique distinct numbers**

IF(FREQUENCY(IF($A7=$A$2:$E$4, COLUMN($A$2:$E$4), ""), COLUMN($A$2:$E$4))>0, ROW($A$1:$A$5), "")

becomes

IF({2;3;2;0;0;0}>0, {1; 2; 3; 4; 5}, "")

and returns

{1; 2; 3; ""; ""}

**Step 4 - Return the k-th smallest value**

SMALL(IF(FREQUENCY(IF($A7=$A$2:$E$4, COLUMN($A$2:$E$4), ""), COLUMN($A$2:$E$4))>0, ROW($A$1:$A$5), ""), COLUMN(A1))

becomes

SMALL({1; 2; 3; ""; ""}, 1)

and returns 1.

**Step 5 - Return the value of a cell at the intersection of a particular row and column**

INDEX($A$1:$E$1, SMALL(IF(FREQUENCY(IF($A7=$A$2:$E$4, COLUMN($A$2:$E$4), ""), COLUMN($A$2:$E$4))>0, ROW($A$1:$A$5), ""), COLUMN(A1)))

becomes

INDEX($A$1:$E$1, 1)

becomes

INDEX({"A", "B", "C", "D", "E"}, 1)

and returns A in cell B7.

**Step 6 - Return value_if_error if expression is an error and the value of the expression itself otherwise**

=IFERROR(INDEX($A$1:$E$1, SMALL(IF(FREQUENCY(IF($A7=$A$2:$E$4, COLUMN($A$2:$E$4), ""), COLUMN($A$2:$E$4))>0, ROW($A$1:$A$5), ""), COLUMN(A1))), "")

becomes

=IFERROR("A", "")

and returns A in cell B7.

**Download excel *.xlsx file**

Match a criterion and extract multiple corresponding table headers.xlsm

Table of Contents Sort a column using array formula Two columns sorting by the second column Sort alphanumeric values I […]

Sort dates within a date range

Question: I have a list of unsorted dates. I want to extract records between two dates and I want the […]

Sort values in parallel (array formula)

Table of contents How to sort a table by Column 1 and then by Column 2 (array formula) How to […]

Lookup and return multiple values sorted in a custom order

Pat asks: Hi Oscar, Thanks for creating such a helpful website and I've a question if I would like to […]

5 easy ways to extract unique distinct values

You have quite a few options to choose from if you are looking for a way to create a unique […]

Extract a unique distinct list from two columns

Question: I have two ranges or lists (List1 and List2) from where I would like to extract an unique distinct […]

Create a unique distinct alphabetically sorted list

The array formula in cell D3 extracts unique distinct values sorted A to Z, from column B to column D. […]

Vlookup – Return multiple unique distinct values

Ahmed Ali asks: How to return multiple values using vlookup in excel and removing duplicates? I have tried the formula […]

Extract a unique distinct list and sum amounts based on a condition

Anura asks: Is it possible to extend this by matching items that meet a criteria? I have a list of […]

### 3 Responses to “Match a criterion and extract multiple corresponding table headers”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Use the img tag, like this: <img src="Insert pic link here">

**Contact Oscar**

You can contact me through this contact form

Is it possible with2 criteria? with intersection table lookup?

Thans in advanced

Azumi

Azumi,

can you explain in greater detail`?

Something Like this (Intersection Tables:

A B C

AA 1 1 2

BB 2 1 2

How to retrieve column headers with this criteria:

1 and AA --> result should be A and B

or

1 and 2 and AA --> result should be A, B and C

Thanks