Index Match Two Ranges

BWMagee

Board Regular
Joined
Feb 18, 2014
Messages
112
Hi, I am trying to match a value that might appear in one of two columns.

My working in english is this:
IF (Sheet 2 Column D = Sheet1 A2) AND (Sheet2 Column A = Sheet1 H1)
INDEX (Return value from Sheet 2 Column C)
OR
IF (Sheet 2 Column C = Sheet1 A2) AND (Sheet2 Column A = Sheet1 H1)
INDEX (Return value from Sheet 2 Column D)

Where:

Sheet1
H1 (contains numerical value "1")
A2 (contains text "Home")

Sheet2
Column A (contains numerical values, "1,2,3" etc... equivalent to H1 in Sheet1)
Column C & D (contains text "home" and "away" ... equivalent to A2 in Sheet2)

If I just searched one range, this formula works:
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Calibri; color: #000000}</style>
=INDEX(Sheet2!$C$1:$C$280,MATCH(1,(Sheet1!$H$1=Sheet2!$A$1:$A$280)*(Sheet1!$A2=Sheet2!$D$1:$D$280),0))


That returns the right value from column C, when we search D for A2. But how do I also return the right value from Column D, when we search C for A2? It would be great if after the formula above I could just write OR(INDEX(.... and just swap the "D" for "C" and vice versa. But I tried that and it didn't work.

Any help much appreciated!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
@BWMagee, I know that what you explained feels clear to you, because you have your sheet in front of you. But for the rest of us, it's not quite as easy to get a grasp of what you're trying to do, where the formulas/results should be going, etc. Can you post some actual data from each sheet, including Column headers and Row numbers, as well as a representation of the desired results placed where you'd like them relative to the other data?
 
Upvote 0
@BWMagee, I know that what you explained feels clear to you, because you have your sheet in front of you. But for the rest of us, it's not quite as easy to get a grasp of what you're trying to do, where the formulas/results should be going, etc. Can you post some actual data from each sheet, including Column headers and Row numbers, as well as a representation of the desired results placed where you'd like them relative to the other data?

Sure thing, appreciate the response!

Sheet1

[TABLE="class: grid, width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]H[/TD]
[TD]I[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Home[/TD]
[TD]1[/TD]
[TD]=Formula[/TD]
[/TR]
</tbody>[/TABLE]

Sheet2

[TABLE="class: grid, width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1
[/TD]
[TD]Home[/TD]
[TD]Neutral[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1
[/TD]
[TD]Away[/TD]
[TD]Home[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1
[/TD]
[TD]Neutral[/TD]
[TD]Away[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2
[/TD]
[TD]Away[/TD]
[TD]Neutral[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]2
[/TD]
[TD]Home[/TD]
[TD]Away[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]2
[/TD]
[TD]Neutral[/TD]
[TD]Home[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]3[/TD]
[TD]Home[/TD]
[TD]Away[/TD]
[/TR]
</tbody>[/TABLE]

So for my formula:
1) Text in Sheet1 H2 ("1") must be found in Sheet2 ColumnA (in this case, A1, A2, A3).
2) When text in Sheet1 A2 ("Home") is found in Column C, I want to return the value in Column D. (in this case row1 = "Neutral")
3) When text in Sheet1 A2 ("Home") is found in Column D, I want to return the value from Column C (in this case row2 = "Away").

In each case there will never be a duplicate of "Home". (Eg. When Column A has text "1", then text "Home" will never be found in both C and D. It will always be one or the other.)

Hope that helps make things clearer!
 
Upvote 0
What is the expected result here: Neutral or Away or both Neutral and Away?

Sorry, I can see I've made an error in my explanation, with "Home" appearing twice in A1. There won't be duplicates so that shouldn't happen. I'll simplify the table:

[TABLE="class: cms_table_grid, width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]Home[/TD]
[TD]Away[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]Hello[/TD]
[TD]Goodbye[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]Please[/TD]
[TD]Anger[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2[/TD]
[TD]Away[/TD]
[TD]Home[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]2[/TD]
[TD]Anger[/TD]
[TD]Please[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]2[/TD]
[TD]Goodbye[/TD]
[TD]Hello[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]3[/TD]
[TD]Anger[/TD]
[TD]Please[/TD]
[/TR]
</tbody>[/TABLE]

In this new example, with "Home" only appearing once when A=1, the expected value would be "Away".
 
Upvote 0
@BWMagee, there are many ways to do this. The following array formula is one (be sure to use Ctrl+Shift+Enter):

Code:
=IFERROR(SUBSTITUTE(INDEX(Sheet1!$C$1:$C$300&Sheet1!$D$1:$D$300,MATCH("*"&$H$2&"*"&$A$2&"*",Sheet1!$A$1:$A$300&Sheet1!$C$1:$C$300&Sheet1!$D$1:$D$300,0)),$A$2,""),"*no match*")
 
Upvote 0
Sorry, I can see I've made an error in my explanation, with "Home" appearing twice in A1. There won't be duplicates so that shouldn't happen. I'll simplify the table:

[TABLE="class: cms_table_grid, width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]Home[/TD]
[TD]Away[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]Hello[/TD]
[TD]Goodbye[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]Please[/TD]
[TD]Anger[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2[/TD]
[TD]Away[/TD]
[TD]Home[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]2[/TD]
[TD]Anger[/TD]
[TD]Please[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]2[/TD]
[TD]Goodbye[/TD]
[TD]Hello[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]3[/TD]
[TD]Anger[/TD]
[TD]Please[/TD]
[/TR]
</tbody>[/TABLE]

In this new example, with "Home" only appearing once when A=1, the expected value would be "Away".

Just enter:

=SUBSTITUTE(LOWER(LOOKUP(9.99999999999999E+307,1/((Sheet2!$A$1:$A$7=$H2)*((Sheet2!$C$1:$C$7=$A2)+(Sheet2!$D$1:$D$7=$A2))),Sheet2!$C$1:$C$7&Sheet2!$D$1:$D$7)),LOWER($A2),"")
 
Upvote 0
Thanks both for your replies, greatly appreciated!

@BWMagee, there are many ways to do this. The following array formula is one (be sure to use Ctrl+Shift+Enter):

Code:
=IFERROR(SUBSTITUTE(INDEX(Sheet1!$C$1:$C$300&Sheet1!$D$1:$D$300,MATCH("*"&$H$2&"*"&$A$2&"*",Sheet1!$A$1:$A$300&Sheet1!$C$1:$C$300&Sheet1!$D$1:$D$300,0)),$A$2,""),"*no match*")

Returns *no match* I'm afraid.

Just enter:

=SUBSTITUTE(LOWER(LOOKUP(9.99999999999999E+307,1/((Sheet2!$A$1:$A$7=$H2)*((Sheet2!$C$1:$C$7=$A2)+(Sheet2!$D$1:$D$7=$A2))),Sheet2!$C$1:$C$7&Sheet2!$D$1:$D$7)),LOWER($A2),"")

Brilliant, works perfectly!
 
Upvote 0
@BWMagee, yup, I only just noticed that your Sheet1 has the H value, not Sheet2; so my formula should have had Sheet2 in all Sheet1 places:

Code:
[COLOR=#333333]=IFERROR(SUBSTITUTE(INDEX(Sheet2!$C$1:$C$300&Sheet2!$D$1:$D$300,MATCH("*"&$H$2&"*"&$A$2&"*",Sheet2!$A$1:$A$300&Sheet2!$C$1:$C$300&Sheet2!$D$1:$D$300,0)),$A$2,""),"*no match*")[/COLOR]

Moot point, however, since you've got Aladin's working.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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