Return values based on multiple cells

SaraWitch

Active Member
Joined
Sep 29, 2015
Messages
378
Office Version
  1. 365
Platform
  1. Windows
Hello peeps,

I am trying to return a value based on multiple cells, and my formula is not working:
¦ MrExcel Queries.xlsm
ABCDEF
1GenderPregnantAdultsChildHousehold CodeShould be
2FemaleNo10#VALUE!SF
3MaleNo10#VALUE!SM
4FemaleYes10#VALUE!pregSF
5FemaleYes20#VALUE!pregC
6MaleNo12#VALUE!SM+
7FemaleNo12#VALUE!SF+
8FemaleYes12#VALUE!SF+
9MaleNo200C
10FemaleNo200C
11FemaleNo21#VALUE!F
12MaleNo22#VALUE!F
Return Multiple Values
Cell Formulas
RangeFormula
E2:E12E2=IF(AND(C2=1,A2="Male"),"SM")*IF(AND(C2=1,A2="Female"),"SF")*IF(AND(C2=1,A2="Female",D2>0),"SF+")*IF(AND(C2=1,A2="Male",D2>0),"SM+")*IF(AND(C2>1,D2>0),"F")*IF(AND(C2>1,B2="Yes"),"pregC")*IF(AND(C2=1,B2="Yes"),"pregSF")

Any help would be appreciated :)
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
why )* between nested IF

you dont have a false condition at the end - so will get FALSE

=IF(AND(C2=1,A2="Male"),"SM",IF(AND(C2=1,A2="Female"),"SF",IF(AND(C2=1,A2="Female",D2>0),"SF+",IF(AND(C2=1,A2="Male",D2>0),"SM+",IF(AND(C2>1,D2>0),"F",IF(AND(C2>1,B2="Yes"),"pregC",IF(AND(C2=1,B2="Yes"),"pregSF")))))))

where is C
Male - NO

Book11
ABCDEF
1GenderPregnantAdultsChildHousehold CodeShould be
2FemaleNo10SFSF
3MaleNo10SMSM
4FemaleYes10SFpregSF
5FemaleYes20pregCpregC
6MaleNo12SMSM+
7FemaleNo12SFSF+
8FemaleYes12SFSF+
9MaleNo20FALSEC
10FemaleNo20FALSEC
11FemaleNo21FF
12MaleNo22FF
Sheet1
Cell Formulas
RangeFormula
E2:E12E2=IF(AND(C2=1,A2="Male"),"SM",IF(AND(C2=1,A2="Female"),"SF",IF(AND(C2=1,A2="Female",D2>0),"SF+",IF(AND(C2=1,A2="Male",D2>0),"SM+",IF(AND(C2>1,D2>0),"F",IF(AND(C2>1,B2="Yes"),"pregC",IF(AND(C2=1,B2="Yes"),"pregSF")))))))


a few differences , in the results - may need investigating further

for example
,IF(AND(C2=1,A2="Female"),"SF",IF(AND(C2=1,A2="Female",D2>0)

because D is not tested in first AND , C2=1 and A2="female" will always give SF as D2 is not considered in the first IF - and so SF+ will never be considered

nested if work left to right
 
Upvote 0
Solution
Here is another approach may be easier to track the formula

Excel Formula:
=IFS(AND($A8="Female", $B8= "No", $C8 =1, $D8 =0), "SF",
AND($A8="Male", $B8= "No", $C8 =1, $D8 =0), "SM",
AND($A8="Female", $B8= "Yes", $C8 =1, $D8 =0), "pregSF",
AND($A8="Female", $B8= "Yes", $C8 =2, $D8 =0), "pregC",
AND($A8="Male", $B8= "No", $C8 =1, $D8 =2), "SM+",
TRUE,""
)

you need to build the rest of it out inbetween the last AND clause the the final TRUE condition
 
Upvote 1
Thank you, @etaf! :biggrin: You're right, I'd also forgotten to add criteria for "C", so adding this and reversing the formula as you suggested worked a treat!
¦ MrExcel Queries.xlsm
ABCDEF
1GenderPregnantAdultsChildHousehold CodeShould be
2FemaleNo10SFSF
3MaleNo10SMSM
4FemaleYes10pregSFpregSF
5FemaleYes20pregCpregC
6MaleNo12SM+SM+
7FemaleNo12SF+SF+
8FemaleYes12SF+SF+
9MaleNo20CC
10FemaleNo20CC
11FemaleNo21FF
12MaleNo22FF
Return Multiple Values
Cell Formulas
RangeFormula
E2:E12E2=IF(AND(C2=1,A2="Female",D2>0),"SF+",IF(AND(C2=1,B2="Yes"),"pregSF",IF(AND(C2=1,A2="Female"),"SF",IF(AND(C2=1,A2="Male",D2>0),"SM+",IF(AND(C2=1,A2="Male"),"SM",IF(AND(C2>1,B2="Yes"),"pregC",IF(AND(C2>1,D2=0),"C",IF(AND(C2>1,D2>0),"F"))))))))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2:F12Expression=F2<>E2textNO
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
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