You are on page 1of 8

4/1/2015

MSExcel:NestedIFFunctions(WS)

MSEXCEL:NESTEDIFFUNCTIONS(WS)
ThisExceltutorialexplainshowtonesttheExcelIFfunctionwithsyntaxandexamples.

DESCRIPTION
ItispossibletonestmultipleIFfunctionswithinoneExcelformula.Youcannestupto7IFfunctions
tocreateacomplexIFTHENELSEstatement.

SYNTAX
ThesyntaxforthenestingtheIFfunctionis:
IF(condition1,value_if_true1,IF(condition2,value_if_true2,value_if_false2))

ThiswouldbeequivalenttothefollowingIFTHENELSEstatement:
IFcondition1THEN
value_if_true1
ELSEIFcondition2THEN
value_if_true2
ELSE
value_if_false2
ENDIF

ParametersorArguments
conditionisthevaluethatyouwanttotest.
value_if_trueisthevaluethatisreturnedifconditionevaluatestoTRUE.
value_if_falseisthevaluethatisreturnifconditionevaluatestoFALSE.

NOTE
ThisNestedIFfunctionsyntaxdemonstrateshowtonesttwoIFfunctions.Youcannestup
to7IFfunctions.

APPLIESTO
TheNestedIFfunctioncanbeusedinthefollowingversionsofMicrosoftExcel:

http://www.techonthenet.com/excel/formulas/if_nested.php

1/8

4/1/2015

MSExcel:NestedIFFunctions(WS)

TheNestedIFfunctioncanbeusedinthefollowingversionsofMicrosoftExcel:
Excel2013,Excel2011forMac,Excel2010,Excel2007,Excel2003,ExcelXP,Excel2000

TYPEOFEXCELFUNCTION
TheNestedIFfunctioncanbeusedinMicrosoftExcelasthefollowingtypeoffunction:
Worksheetfunction(WS)

EXAMPLE(ASWORKSHEETFUNCTION)
Let'slookatanexampletoseehowyouwoulduseaNestedIFexamplesandexplorehowtousethe
NestedIFfunctionasaworksheetfunctioninMicrosoftExcel:

Basedonthespreadsheetabove,thefollowingExcelNestedIFexampleswouldreturn:
=IF(A1="10x12",120,IF(A1="8x8",64,IF(A1="6x6",36)))
Result:120
=IF(A2="10x12",120,IF(A2="8x8",64,IF(A2="6x6",36)))
Result:64
=IF(A3="10x12",120,IF(A3="8x8",64,IF(A3="6x6",36)))
Result:36

FREQUENTLYASKEDQUESTIONS
Question:

InMicrosoftExcel,Ineedtowriteaformulathatworksthisway:
http://www.techonthenet.com/excel/formulas/if_nested.php

2/8

4/1/2015

MSExcel:NestedIFFunctions(WS)

Question: InMicrosoftExcel,Ineedtowriteaformulathatworksthisway:
If(cellA1)islessthan20,thenmultiplyby1,
Ifitisgreaterthanorequalto20butlessthan50,thenmultiplyby2
Ifitsisgreaterthanorequalto50andlessthan100,thenmultiplyby3
Andifitisgreatorequaltothan100,thenmultiplyby4

Answer: YoucanwriteanestedIFstatementtohandlethis.Forexample:
=IF(A1<20,A1*1,IF(A1<50,A1*2,IF(A1<100,A1*3,A1*4)))

Question: InExcel,IneedaformulaincellC5thatdoesthefollowing:
IFA1+B1<=4,return$20
IFA1+B1>4but<=9,return$35
IFA1+B1>9but<=14,return$50
IFA1+B1>15,return$75

Answer: IncellC5,youcanwriteanestedIFstatementthatusestheANDfunctionasfollows:
=IF((A1+B1)<=4,20,IF(AND((A1+B1)>4,(A1+B1)<=9),35,IF(AND((A1+B1)>9,(A1+B1)<=14),50,75)))

Question: InMicrosoftExcel,Ineedaformulaforthefollowing:
IFcellA1=PRADIPthenvaluewillbe100
IFcellA1=PRAVINthenvaluewillbe200
IFcellA1=PARTHAthenvaluewillbe300
IFcellA1=PAVANthenvaluewillbe400

Answer: YoucanwriteanIFstatementasfollows:
=IF(A1="PRADIP",100,IF(A1="PRAVIN",200,IF(A1="PARTHA",300,IF(A1="PAVAN",400,""))))

Question: InMicrosoftExcel,Iwanttocalculatefollowingusingan"if"formula:
ifA1<100,000thenA1*.1%butminimum25
andifA1>1,000,000thenA1*.01%butmaximum5000

Answer: YoucanwriteanestedIFstatementthatusestheMAXfunctionandtheMINfunctionas
follows:
=IF(A1<100000,MAX(25,A1*0.1%),IF(A1>1000000,MIN(5000,A1*0.01%),""))
http://www.techonthenet.com/excel/formulas/if_nested.php

3/8

4/1/2015

MSExcel:NestedIFFunctions(WS)

Question: IhaveExcel2000.IfcellA2isgreaterthanorequalto0thenaddtoC1.IfcellB2is
greaterthanorequalto0thensubtractfromC1.IfbothA2andB2areblankthenequalsC1.Canyou
helpmewiththeIFfunctiononthisone?

Answer: YoucanwriteanestedIFstatementthatusestheANDfunctionandtheISBLANKfunction
asfollows:
=IF(AND(ISBLANK(A2)=FALSE,A2>=0),C1+A2,IF(AND(ISBLANK(B2)=FALSE,B2>=0),C1B2,
IF(AND(ISBLANK(A2)=TRUE,ISBLANK(B2)=TRUE),C1,"")))

Question: HowwouldIwritethisequationinExcel?IfD12<=0thenD12*L12,IfD12is>0but
<=600thenD12*F12,IfD12is>600then((600*F12)+((D12600)*E12))

Answer: YoucanwriteanestedIFstatementasfollows:
=IF(D12<=0,D12*L12,IF(D12>600,((600*F12)+((D12600)*E12)),D12*F12))

Question: IhavereadyourpieceonnestedIFsinExcel,butIstillcannotworkoutwhatiswrong
withmyformulapleasecouldyouhelp?HereiswhatIhave:
=IF(63<=A2<80,1,IF(80<=A2<95,2,IF(A2=>95,3,0)))

Answer: ThesimplestwaytowriteyournestedIFstatementbasedonthelogicyoudescribeabove
is:
=IF(A2>=95,3,IF(A2>=80,2,IF(A2>=63,1,0)))

Thisformulawilldothefollowing:
IfA2>=95,theformulawillreturn3(firstIFfunction)
IfA2<95andA2>=80,theformulawillreturn2(secondIFfunction)
IfA2<80andA2>=63,theformulawillreturn1(thirdIFfunction)
IfA2<63,theformulawillreturn0

Question: I'mverynewtotheExcelworld,andI'mtryingtofigureouthowtosetuptheproper
formulaforanIf/thencell.
WhatI'mtryingforis:
IfB2'svalueis1to5,thenmultiplyE2by.77

http://www.techonthenet.com/excel/formulas/if_nested.php

4/8

4/1/2015

MSExcel:NestedIFFunctions(WS)

IfB2'svalueis1to5,thenmultiplyE2by.77
IfB2'svalueis6to10,thenmultiplyE2by.735
IfB2'svalueis11to19,thenmultiplyE2by.7
IfB2'svalueis20to29,thenmultiplyE2by.675
IfB2'svalueis30to39,thenmultiplyE2by.65

I'vetriedafewdifferentthingsthinkingIwasontherighttrackbasedontheIF,andANDfunction
tutorialshere,butIcan'tseemtogetitright.

Answer: TowriteyourIFformula,youneedtonestmultipleIFfunctionstogetherincombinationwith
theANDfunction.
Thefollowingformulashouldworkforwhatyouaretryingtodo:
=IF(AND(B2>=1,B2<=5),E2*0.77,IF(AND(B2>=6,B2<=10),E2*0.735,IF(AND(B2>=11,B2<=19),
E2*0.7,IF(AND(B2>=20,B2<=29),E2*0.675,IF(AND(B2>=30,B2<=39),E2*0.65,"")))))

Asonefinalcomponentofyourformula,youneedtodecidewhattodowhennoneoftheconditions
aremet.Inthisexample,wehavereturned""whenthevalueinB2doesnotmeetanyoftheIF
conditionsabove.

Question: IhaveanestingORfunctionproblem:
Mynonworkingformulais:
=IF(C9=1,K9/J7,IF(C9=2,K9/J7,IF(C9=3,K9/L7,IF(C9=4,0,K9/N7))))

InCellC9,Icanhaveaninputof1,2,3,4or0.Theproblemisonhowtowritethe"or"conditionwhen
a"4or0"existsinColumnC.Ifthe"4or0"conditionsexistsinColumnCIwantColumnKdividedby
ColumnNandtheanswertobeplacedinColumnMandassociatedrow

Answer: YoushouldbeabletousetheORfunctionwithinyourIFfunctiontotestforC9=4ORC9=0
asfollows:
=IF(C9=1,K9/J7,IF(C9=2,K9/J7,IF(C9=3,K9/L7,IF(OR(C9=4,C9=0),K9/N7))))

ThisformulawillreturnK9/N7ifcellC9iseither4or0.

Question: InExcel,Iamtryingtocreateaformulathatwillshowthefollowing:
IfcolumnB=RossandcolumnC=8thenincellABofthatrowIwantittoshow2013,IfcolumnB=
BlockandcolumnC=9thenincellABofthatrowIwantittoshow2012.

Answer: YoucancreateyourExcelformulausingnestedIFfunctionswiththeANDfunction.
=IF(AND(B1="Ross",C1=8),2013,IF(AND(B1="Block",C1=9),2012,""))

http://www.techonthenet.com/excel/formulas/if_nested.php

5/8

4/1/2015

MSExcel:NestedIFFunctions(WS)

=IF(AND(B1="Ross",C1=8),2013,IF(AND(B1="Block",C1=9),2012,""))

Thisformulawillreturn2013asanumericvalueifB1is"Ross"andC1is8,or2012asanumeric
valueifB1is"Block"andC1is9.Otherwise,itwillreturnblank,asdenotedby"".

Question: InExcel,Ireallyhaveaproblemlookingfortherightformulatoexpressthefollowing:
IfB1=0,C1isequaltoA1/2
IfB1=1,C1isequaltoA1/2times20%
IfD1=1,C1isequaltoA1/25
I'vebeentryingtolookforanysameexpressionsinyoursite.Pleasehelpmefixthis.

Answer: IncellC1,youcanusethefollowingExcelformulawith3nestedIFfunctions:
=IF(B1=0,A1/2,IF(B1=1,(A1/2)*0.2,IF(D1=1,(A1/2)5,"")))

Pleasenotethatifnoneoftheconditionsaremet,theExcelformulawillreturn""astheresult.

Question: InExcel,whathaveIdonewrongwiththisformula?
=IF(OR(ISBLANK(C9),ISBLANK(B9)),"",IF(ISBLANK(C9),D9TODAY(),"Reactivated"))

IwanttomakeaneventthatifB9andC9isempty,thevaluewouldbeempty.IfonlyC9isempty,
thentheoutputwouldbetheremainingdaysleftbetweenthetwodates,andifthetwocellsarenot
empty,theoutputshouldbethestring'Reactivated'.
TheproblemwiththiscodeisthatIF(ISBLANK(C9),D9TODAY()isnotworking.

Answer: Firstofall,youmightwanttoreplaceyourORfunctionwiththeANDfunction,sothatyour
ExcelIFformulalookslikethis:
=IF(AND(ISBLANK(C9),ISBLANK(B9)),"",IF(ISBLANK(C9),D9TODAY(),"Reactivated"))

Next,makesurethatyoudon'thaveanyabnormalformattinginthecellthatcontainstheresults.To
besafe,rightclickonthecellthatcontainstheformulaandchooseFormatCellsfromthepopup
menu.WhentheFormatCellswindowappears,selecttheNumbertab.ChooseGeneralastheformat
andclickontheOKbutton.

Question: I'mlookingtoreturnananswerfromanumber'n'thatneedstosatisfyacertainrange
criteria.NewstampdutycalculatorsforUKpropertysetbandsforpercentagestampdutyasfollows:
0125000=0%
125001250000=2%

http://www.techonthenet.com/excel/formulas/if_nested.php

6/8

4/1/2015

125001250000=2%
250001975000=5%
9750011500000=10%
>1500000=12%

MSExcel:NestedIFFunctions(WS)

Irealiseit'sprobablyan'IF(AND)'functionbutIappeartorequiretoomanyarguments.Canyouhelp?

Answer: YoucancreatethisformulausingnestedIFfunctions.Wewillassumethatyournumber'n'
residesincellB1.Youcancreateyourformulaasfollows:
=IF(B1>1500000,B1*0.12,IF(B1>=975001,B1*0.1,IF(B1>=250001,B1*0.05,
IF(B1>=125001,B1*0.02,0))))

SinceyourIFconditionswillcoverallnumbersintherangeof0to>1500000,itiseasiesttowork
backwardsstartingwiththe>1500000condition.Excelwillevaluateeachconditionandstopwhena
conditionisTRUE.ThisiswhywecansimplifytheformulaswithinthenestedIFfunctions,insteadof
testingrangesusingtwocomparisonssuchasAND(B1>=125001,B1<=250000).

Question: Let'sexpandthelastquestionfurtherandassumethatweneedtocalculatepercentages
basedontiers(notjustonthevalueaswhole):
0125000=0%
125001250000=2%
250001975000=5%
9750011500000=10%
>1500000=12%
SayIenter1,000,000inB1.Thefirst125,000attracts0%,thenext125,000to250,000attracts2%,
andsoon.

Answer: Thisaddsalevelofcomplexitytoourformulasincewehavetocalculateeachrangeofthe
numberusingadifferentpercentage.
Wecancreatethissolutionwiththefollowingformula:
=IF(B1<=125000,0,IF(B1<=250000,(B1125000)*0.02,IF(B1<=975000,(125000*0.02)+((B1
250000)*0.05),IF(B1<=1500000,(125000*0.02)+(725000*0.05)+((B1975000)*0.1),
(125000*0.02)+(725000*0.05)+(525000*0.1)+((B11500000)*0.12)))))

Ifthevaluewasbelow125,000,theformulawouldreturn0.
Ifthevalueisbetween125,001and250,000,itwouldcalculate0%onthefirst125,000and2%onthe
remainder.
Ifthevalueisbetween250,001and250,001,itwouldcalculate0%onthefirst125,000,2%onthenext
125,000and5%ontheremainder.
Andsoon....
http://www.techonthenet.com/excel/formulas/if_nested.php

7/8

4/1/2015

Andsoon....

http://www.techonthenet.com/excel/formulas/if_nested.php

MSExcel:NestedIFFunctions(WS)

8/8