Match with multiple columns

topi1

Active Member
Joined
Aug 6, 2014
Messages
252
Office Version
  1. 2010
In the following example, I have a list of fruits and vegetables in Column A. Columns D and E have names of few fruits and vegetables. In the column B, I have entered countif formula to see if the object in the column A is a fruit or vegetable. The formula works but in real life I have numerous columns and not just D & E, and I don't know how to write something which will look at each of those columns and then get the answer which will be equal to the first row of the matched column. B will be blank if unmatched. Thank you in advance.

Book2
ABCDE
1VegetableFruit
2CarrotsGrapes
3BroccoliVegetableBroccoliBanana
4OrangeFruitSpinachOrange
5SpinachVegetablecucumbersApple
6AppleFruit
7
8
9
10
11
12
13
14
15
Sheet1
Cell Formulas
RangeFormula
B3:B6B3=IF((COUNTIF($D$2:$D$15,$A3)=1),$D$1,IF((COUNTIF($E$2:$E$15,$A3)=1),$E$1,""))
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try

varios 13ene2024.xlsm
ABCDEF
1VegetableFruitLiquid
2CarrotsGrapesVino
3BroccoliVegetableBroccoliBanana
4OrangeFruitSpinachOrange
5SpinachVegetablecucumbersApple
6AppleFruit
7VinoLiquid
Hoja6
Cell Formulas
RangeFormula
B3:B7B3=INDEX($D$1:$F$1,SUMPRODUCT(($D$2:$F$5=A3)*COLUMN($D$1:$F$1))-COLUMN($D$1)+1)
 
Upvote 0
Fantastic, Thank you so much for your prompt help. For now, I extended data range to more rows and columns as follows.

INDEX($D$1:$ZZ$1,SUMPRODUCT(($D$2:$ZZ$500=A3)*COLUMN($D$1:$ZZ$1))-COLUMN($D$1)+1)

Thank you again.
 
Upvote 0
@DanteAmor Can you please modify the formula so it will not give "0" as a result if the item in the D onwards column is duplicated. For example, spinach is in D4. If I add spinach in D6, B5 becomes "0". I would like the formula to ignore duplicates and yield "vegetables" even if D4 and D6 have spinach. Thank you.
 
Upvote 0
For example, spinach is in D4. If I add spinach in D6

Try:
Dante Amor
ABCDEF
1VegetableFruitLiquid
2CarrotsGrapesVino
3BroccoliVegetableBroccoliBanana
4OrangeFruitSpinachOrange
5SpinachVegetablecucumbersApple
6AppleFruitSpinach
7VinoLiquid
Hoja6
Cell Formulas
RangeFormula
B3:B7B3=INDEX($D$1:$F$1,MAX(($D$2:$F$8=A3)*(COLUMN(D1:F1)))-COLUMN($D$1)+1)
Press CTRL+SHIFT+ENTER to enter array formulas.



That is an array formula, to enter it, you must edit it and press the 3 keys Shift + Control + Enter (Not just Enter)
If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself.
😇
 
Upvote 0
Thank you @DanteAmor . I am getting Vegetables in B3 to B7.

Book3
ABCDEF
1VegetableFruitLiquid
2CarrotsGrapesVino
3BroccoliVegetableBroccoliBanana
4OrangeVegetableSpinachOrange
5SpinachVegetablecucumbersApple
6AppleVegetableSpinach
7VinoVegetable
Sheet2
Cell Formulas
RangeFormula
B3:B7B3=INDEX($D$1:$F$1,MAX(($D$2:$F$8=A3)*(COLUMN(D1:F1)))-COLUMN($D$1)+1)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
My fault.
The absolute reference was missing in $D$1:$F$1

varios 13ene2024b.xlsm
ABCDEF
1VegetableFruitLiquid
2CarrotsGrapesVino
3BroccoliVegetableBroccoliBanana
4OrangeFruitSpinachOrange
5SpinachVegetablecucumbersApple
6AppleFruitSpinach
7VinoLiquid
Hoja6
Cell Formulas
RangeFormula
B3:B7B3=INDEX($D$1:$F$1,MAX(($D$2:$F$8=A3)*(COLUMN($D$1:$F$1)))-COLUMN($D$1)+1)
Press CTRL+SHIFT+ENTER to enter array formulas.



No, that's not the problem.

The problem is that you must put the formula in cell B3, edit it, press the 3 keys Shift + Control + Enter and then copy the formula down.
It seems you are selecting all cells B3 to B7 and then pressing the 3 keys and that is not how it should be.
 
Upvote 0
Solution
Sorry to keep bothering you but it did not help.

Book3
ABCDEF
1VegetableFruitLiquid
2CarrotsGrapesVino
3BroccoliVegetableBroccoliBanana
4OrangeVegetableSpinachOrange
5SpinachVegetablecucumbersApple
6AppleVegetableSpinach
7VinoVegetable
Sheet2
Cell Formulas
RangeFormula
B3:B7B3=INDEX($D$1:$F$1,MAX(($D$2:$F$8=A3)*(COLUMN($D$1:$F$1)))-COLUMN($D$1)+1)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
@DanteAmor tried again after rebooting. Even tried without any repeats. Did not work. Any help would be greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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