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
ID
Values Attributes AAAA, BBBB or CCCC
Values Attributes DDDD or EEEE

<tbody>
</tbody>

Sheet 2
ID
Attribute
Value
1
AAAA
10
1
DDDD
15
2
BBBB
20
3
CCCC
25
4
BBBB
30
4
EEEE
35
5
EEEE
40

<tbody>
</tbody>

I want the result to be this for Sheet 1:
ID
Value AAAA BBBB or CCCC (V1)
Value DDDD or EEEE (V2)
1
10
15
2
20
3
25
4
30
35

<tbody>
</tbody>

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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,214,657
Messages
6,120,764
Members
448,991
Latest member
Hanakoro

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