IF + INDEX-MATCH and return value from different cell

davidov

New Member
Joined
Aug 1, 2017
Messages
11
Last time I asked here something this forum was very helpful, so I hope one of you can help me with my next problem.

I have data in one sheet, with an ID number, Attributes that go with it and corresponding values. But one ID can have multiple attributes and values. And this data has to be transferred to another sheet. To try I made a simple sheet set up, which I can translate easily in a final version, but I am already failing in the trial file. I have 2 sheets in total:
Sheet1
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Values Attributes AAAA, BBBB or CCCC
[/TD]
[TD]Values Attributes DDDD or EEEE
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Sheet 2
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Attribute
[/TD]
[TD]Value
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]AAAA
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]DDDD
[/TD]
[TD]15
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]BBBB
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]CCCC
[/TD]
[TD]25
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]BBBB
[/TD]
[TD]30
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]EEEE
[/TD]
[TD]35
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]EEEE
[/TD]
[TD]40
[/TD]
[/TR]
</tbody>[/TABLE]

I want the result to be this for Sheet 1:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID
[/TD]
[TD]Value AAAA BBBB or CCCC (V1)
[/TD]
[TD]Value DDDD or EEEE (V2)
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]10
[/TD]
[TD]15
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]20
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]25
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]30
[/TD]
[TD]35
[/TD]
[/TR]
</tbody>[/TABLE]

What formula to use? So far I used IF statements to check if there is an AAAA, if not go to BBBB, if not go to CCCC. There will never be a value for both AAAA and BBBB or CCCC at the same time.
My formula for V1:
=IF(INDEX(Sheet2!$B:$B,MATCH($A2,Sheet2!$A:$A,0))="AAAA",
INDEX(Sheet2!$C:$C,MATCH($A2,Sheet2!$A:$A,0)),
IF(INDEX(Sheet2!$B:$B,MATCH($A2,Sheet2!$A:$A,0))="BBBB",
INDEX(Sheet2!$C:$C,MATCH($A2,Sheet2!$A:$A,0)),
IF(INDEX(Sheet2!$B:$B,MATCH($A2,Sheet2!$A:$A,0))="CCCC",
INDEX(Sheet2!$C:$C,MATCH($A2,Sheet2!$A:$A,0)),"")))

This kind of works, but only if every ID only has 1 Attribute. If I adjust this formula for V2 it will work fine as well as long there is no value for V1. At the moment there is a value for both V1 as for V2 it fills in only the column with the first Attribute in the list of sheet 2.

I tried index-match with criterion but could not make it work, and I tried index-match-match but I am not that good with it. Does anyone know a formula I can use that will give the desired result, without using macros. I try to make it so that other people who will use this file don't have to worry about macros as they are likely to be even less knowledgeable about it than me.

Thanks in regard! :)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
There's probably a more elegant solution but here's my stab:


Book1
ABC
1IDAttributeValue
21AAAA10
31DDDD15
42BBBB20
53CCCC25
64BBBB30
74EEEE35
85EEEE40
Sheet2



Book1
ABC
1IDValue AAAA BBBB or CCCCValue DDDD or EEEE
211015
3220
4325
543035
Sheet1
Cell Formulas
RangeFormula
B2{=IFERROR(1/(1/MAX(IF(Sheet2!$A$2:$A$8=$A2,IF(IFERROR(FIND(Sheet2!$B$2:$B$8&"~","AAAA~BBBB~CCCC~"),0)>0,Sheet2!$C$2:$C$8)))),"")}
C2{=IFERROR(1/(1/MAX(IF(Sheet2!$A$2:$A$8=$A2,IF(IFERROR(FIND(Sheet2!$B$2:$B$8&"~","DDDD~EEEEE~"),0)>0,Sheet2!$C$2:$C$8)))),"")}
Press CTRL+SHIFT+ENTER to enter array formulas.


WBD
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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