To many IF's for xl2003

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
333
Office Version
  1. 2010
Platform
  1. Windows
I have been informed that xl2003 can only use up to 7 IF statements and if I have to use more than this then there is probably a better way to create the formula.

I of course have no idea how to improve on the formula otherwise I wouldn't need to post it. So here is the formula I can use in xl2010, but can't in xl2003:


Excel 2010
D
2FLU1
Sheet1
Cell Formulas
RangeFormula
D2=IF(DATE(1938,9,1)>=$B2,"FLU2",IF(DATE(1948,9,1)>=$B2,"FLU1",IF(DATE(1948,9,1)<$B2,IF(L2="Carer","ZFCARE",IF(L2="Chronic Heart Disease","ZFCHD",IF(L2="Chronic Liver Disease","ZFCLD",IF(L2="Chronic Neurological Disease","ZFCNS",IF(L2="Chronic Renal Disease","ZFCRD",IF(L2="Chronic Respiratory Disease","ZFCRES",IF(L2="Diabetes","ZFDM",IF(L2="Long-stay residential","ZFHOME",IF(L2="Immunosuppression","ZFIMM",IF(L2="Pregnant","ZFPREG",IF(L2="Stroke / TIA","ZFSTIA",IF(AND(B2<=DATE(2010,9,1),B2>DATE(2009,9,1)),"ZLF3",IF(AND(B2<=DATE(2011,9,1),B2>DATE(2010,9,1)),"ZFL2",IF(L2="","Unidentified",)))))))))))))),"N/A")))


Here is the table of data I need to find the correct code for in cell D. My above formula doesn't include Pneumcoccal as I was busy trying to get the FLU to work, but Pneumo will have to use the text in IMMTYPE column J to workout the code

Excel 2003
ABCDEFGHIJKL
1IDDOB01/09/2013CodeIMMSTYPESTAGEREASONTXT
220/02/194469y 6m 12dFLU1FLU
302/11/1910102y 9m 30dFLU2FLU
421/09/194270y 11m 11dPNEUPNEUMOPOLY
512/11/197042y 9m 20dZFDMFLUDiabetes
603/08/196350y 0m 29dZFCRESFLUChronic Respiratory Disease
703/11/196250y 9m 29dZFSTIAFLUStroke / Tia
817/03/196350y 5m 15dZFDMFLUDiabetes
915/01/196746y 7m 17dZFCRDFLUChronic Renal Disease
1020/10/196943y 10m 12dZFCHDFLUChronic Heart Disease
1105/10/196349y 10m 27dZFCNSFLUChronic Neurological Disease
1213/04/196053y 4m 19dZFCRESFLUChronic Respiratory Disease
1309/12/196943y 8m 23dZFSTIAFLUStroke / Tia
1428/10/196943y 10m 4dUnidentifiedFLU
1501/09/20112y 0m 0dZFL2FLUSIN1
1601/09/20103y 0m 0dZLF3FLU
1702/01/20058y 7m 30dZFCRESFLUSIN1Chronic Respiratory Disease
1808/01/20058y 7m 24dZFCRDFLUSIN1Chronic Renal Disease
1901/08/20112y 1m 0dPNCHMGPNEUMOCONJ13
Sheet1


Here are the rules that make up the code in column D

Excel 2003
AB
1CodeDescription
2FLU1INFLUENZA VACC AGE 65 - 74
3FLU2INFLUENZA VACC AGED 75 AND OVER
4ZFCAREFLU VACC <65 AT RISK MAIN CARER
5ZFCHDFLU VACC <65 AT RISK CHRONIC HEART DISEASE
6ZFCLDFLU VACC <65 AT RISK CHRONIC LIVER DISEASE
7ZFCNSFLU VACC <65 AT RISK NEUROLOGICAL DISEASE
8ZFCRDFLU VACC <65 AT RISK CHRONIC RENAL DISEASE
9ZFCRESFLU VACC <65 AT RISK RESPIRATORY DISEASE
10ZFDMFLU VACC <65 AT RISK DIABETES MELLITUS
11ZFHOMEFLU VACC <65 AT RISK CARE HOME RESIDENT
12ZFIMMFLU VACC <65 AT RISK IMMUNOSUPPRESSED
13ZFPREGFLU VACC <65 AT RISK PREGNANT WOMEN
14ZFSTIAFLU VACC <65 AT RISK STROKE TIA
15PNEUPNEUMOCOCCAL INJECTION AGE 65 AND OVER
16PNCHMGCHILD PNEUMO VACC FINAL DOSE UNDER 5
17ZFL2INFLUENZA 2 YEAR OLDS
18ZFL3INFLUENZA 3 YEAR OLDS
Sheet2


Any help in this would be most appreciated as I have hundreds to check through
 
Just to repeat, my table does not change your existing table. It's a DIFFERENT table that enables the use of a simple formula.

I'll leave you in Mark's hands.
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Just to repeat, my table does not change your existing table. It's a DIFFERENT table that enables the use of a simple formula.

I'll leave you in Mark's hands.

I agree with Shg, but if you want a formula without table, here you have another (a big formula too):

Code:
Use only Enter to enter the formula

=IF(DATEDIF(B2,$C$1,"y")>=75,"FLU2",IF(DATEDIF(B2,$C$1,"y")>=65,"FLU1",IF(L2<>"",
VLOOKUP($L2,{"Carer","ZFCARE";"Chronic Heart Disease","ZFCHD";"Chronic Liver Disease","ZFCLD";"Chronic Neurological Disease","ZFCNS";"Chronic Renal Disease",
"ZFCRD";"Chronic Respiratory Disease","ZFCRES";"Diabetes","ZFDM";"Long-stay residential","ZFHOME";"Immunosuppression","ZFIMM";"Pregnant","ZFPREG";"Stroke / TIA","ZFSTIA"},2,0),
IF(DATEDIF(B2,$C$1,"y")=3,"ZFL3",IF(DATEDIF(B2,$C$1,"y")=2,"ZFL2",IF(J2="PNEUMOCOCONJ13","PNCHMG",IF(J2="PNEUMOPOLY","PNEU","UNIDENTIFIED")))))))


Markmzz
 
Upvote 0
Here is my last formula with the table of the post#5:

Code:
=IF(DATEDIF(B2,$C$1,"y")>=75,"FLU2",IF(DATEDIF(B2,$C$1,"y")>=65,"FLU1",IF(L2<>"",
VLOOKUP($L2,$N$2:$O$12,2,0),
IF(DATEDIF(B2,$C$1,"y")=3,"ZFL3",
IF(DATEDIF(B2,$C$1,"y")=2,"ZFL2",
IF(J2="PNEUMOCOCONJ13","PNCHMG",IF(J2="PNEUMOPOLY","PNEU","UNIDENTIFIED")))))))

PS: you can put that table in another sheet.

Markmzz
 
Upvote 0
Less if's

=CHOOSE(MATCH(YEAR(C1)-YEAR(B2);{0;2;3;65;75;100};1);IF(L2="";"";CHOOSE(MATCH($L2;{"Carer";"Chronic Heart Disease";"Chronic Liver Disease";"Chronic Neurological Disease";"Chronic Renal Disease";"Chronic Respiratory Disease";"Diabetes";"Long-stay residential";"Immunosuppression";"Pregnant";"Stroke / TIA"};0);"ZFCARE";"ZFCHD";"ZFCLD";"ZFCNS";"ZFCRD";"ZFCRES";"ZFDM";"ZFHOME";"ZFIMM";"ZFPREG";"ZFSTIA")) & IF(J2="PNEUMOCOCONJ13";"PNCHMG";IF(J2="PNEUMOPOLY";"PNEU";"UNIDENTIFIED"));"ZLF2";"ZLF3";"FLU1";"FLU2")
 
Upvote 0
Another small modification:

Code:
=IF(DATEDIF(B2,$C$1,"y")>=75,"FLU2",IF(DATEDIF(B2,$C$1,"y")>=65,"FLU1",IF(L2<>"",
VLOOKUP($L2,$N$2:$O$12,2,0),
IF(OR(DATEDIF(B2,$C$1,"y")={2;3}),"ZFL"&DATEDIF(B2,$C$1,"y"),
IF(J2="PNEUMOCOCONJ13","PNCHMG",IF(J2="PNEUMOPOLY","PNEU","UNIDENTIFIED"))))))


Markmzz
 
Upvote 0
A small modification:

Code:
With table

=IF(DATEDIF(B2,$C$1,"y")>=75,"FLU2",IF(DATEDIF(B2,$C$1,"y")>=65,"FLU1",IF(L2="",
IF(OR(DATEDIF(B2,$C$1,"y")={2;3}),"ZFL"&DATEDIF(B2,$C$1,"y"),
IF(J2="PNEUMOCOCONJ13","PNCHMG",IF(J2="PNEUMOPOLY","PNEU","UNIDENTIFIED"))),
VLOOKUP($L2,$N$2:$O$12,2,0))))

Without table

=IF(DATEDIF(B2,$C$1,"y")>=75,"FLU2",IF(DATEDIF(B2,$C$1,"y")>=65,"FLU1",IF(L2="",
IF(OR(DATEDIF(B2,$C$1,"y")={2;3}),"ZFL"&DATEDIF(B2,$C$1,"y"),
IF(J2="PNEUMOCOCONJ13","PNCHMG",IF(J2="PNEUMOPOLY","PNEU","UNIDENTIFIED"))),
VLOOKUP($L2,{"Carer","ZFCARE";"Chronic Heart Disease","ZFCHD";"Chronic Liver Disease",
"ZFCLD";"Chronic Neurological Disease","ZFCNS";"Chronic Renal Disease","ZFCRD";"Chronic Respiratory Disease",
"ZFCRES";"Diabetes","ZFDM";"Long-stay residential","ZFHOME";"Immunosuppression","ZFIMM";"Pregnant","ZFPREG";"Stroke / TIA","ZFSTIA"},2,0))))

Markmzz
 
Last edited:
Upvote 0
OMG! This is what dreams are made of :)

I sort of understand your formula (although I would never have been able to accomplish it. It's one thing reading it and it’s an entirely different ball game writing it)

Thank you ever so much for this, it will save me so much time.

I'm continually amazed what can be achieved in XL.

Thank you, Thank You, Thank, You.......
 
Upvote 0
OMG! This is what dreams are made of :)

I sort of understand your formula (although I would never have been able to accomplish it. It's one thing reading it and it’s an entirely different ball game writing it)

Thank you ever so much for this, it will save me so much time.

I'm continually amazed what can be achieved in XL.

Thank you, Thank You, Thank, You.......

You're welcome.

And I'm glad that your problem was solved and thank you for the feedback.

Markmzz
 
Upvote 0
I'm probably pushing my luck here, but I'm so happy that it works and i will be using it a lot, so i thought I would stick in in a macro, but it keeps stopping with an error message:

Runtime error 1004
Unable to set the FormulaArray property of the range class

...here is the VBA code of the formula
Code:
    Range("D2").Select
    Selection.FormulaArray = _
        "=IF(RC2<=1*""1/9/1938"",""FLU2"",IF(RC2<=1*""1/9/1948"",""FLU1"",IF(OR(RC12={""Carer"";""Chronic Heart Disease"";""Chronic Liver Disease"";""Chronic Neurological Disease"";""Chronic Renal Disease"";""Chronic Respiratory Disease"";""Diabetes"";""Long-stay residential"";""Immunosuppression"";""Pregnant"";""Stroke / TIA""}),VLOOKUP(RC12,{""Carer"",""ZFCARE"";""Chronic " & _
        "Heart Disease"",""ZFCHD"";""Chronic Liver Disease"",""ZFCLD"";""Chronic Neurological Disease"",""ZFCNS"";""Chronic Renal Disease"",""ZFCRD"";""Chronic Respiratory Disease"",""ZFCRES"";""Diabetes"",""ZFDM"";""Long-stay residential"",""ZFHOME"";""Immunosuppression"",""ZFIMM"";""Pregnant"",""ZFPREG"";""Stroke / TIA"",""ZFSTIA""},2,0),IF(OR(RC10={""PNEUMOPOLY"";""PNEUMOCONJ13""" & _
        "}),VLOOKUP(RC10,{""PNEUMOPOLY"",""PNEU"";""PNEUMOCONJ13"",""PNCHMG""},2,0),IF(AND(RC2<=1*""1/9/2010"",RC2>1*""1/9/2009""),""ZLF3"",IF(AND(RC2<=1*""1/9/2011"",RC2>1*""1/9/2010""),""ZFL2"",IF(RC12="""",""Unidentified"",""N/A"")))))))"

...and here is the final formula I am using:

Excel 2010
D
2FLU2
Upload Data
Cell Formulas
RangeFormula
D2{=IF($B2<=1*"1/9/1938","FLU2",IF($B2<=1*"1/9/1948","FLU1",IF(OR($L2={"Carer";"Chronic Heart Disease";"Chronic Liver Disease";"Chronic Neurological Disease";"Chronic Renal Disease";"Chronic Respiratory Disease";"Diabetes";"Long-stay residential";"Immunosuppression";"Pregnant";"Stroke / TIA"}),VLOOKUP($L2,{"Carer","ZFCARE";"Chronic Heart Disease","ZFCHD";"Chronic Liver Disease","ZFCLD";"Chronic Neurological Disease","ZFCNS";"Chronic Renal Disease","ZFCRD";"Chronic Respiratory Disease","ZFCRES";"Diabetes","ZFDM";"Long-stay residential","ZFHOME";"Immunosuppression","ZFIMM";"Pregnant","ZFPREG";"Stroke / TIA","ZFSTIA"},2,0),IF(OR($J2={"PNEUMOPOLY";"PNEUMOCONJ13"}),VLOOKUP($J2,{"PNEUMOPOLY","PNEU";"PNEUMOCONJ13","PNCHMG"},2,0),IF(AND($B2<=1*"1/9/2010",$B2>1*"1/9/2009"),"ZLF3",IF(AND($B2<=1*"1/9/2011",$B2>1*"1/9/2010"),"ZFL2",IF($L2="","Unidentified","N/A")))))))}
Press CTRL+SHIFT+ENTER to enter array formulas.


The macro doesn't seem to record the formula properly either, because when it creates a line break it looses bits of the formula, but I think I have resolved this with the code shown above.

I just keep getting the error message now.
 
Upvote 0
I'm probably pushing my luck here, but I'm so happy that it works and i will be using it a lot, so i thought I would stick in in a macro, but it keeps stopping with an error message:

Runtime error 1004
Unable to set the FormulaArray property of the range class

...here is the VBA code of the formula
Code:
    Range("D2").Select
    Selection.FormulaArray = _
        "=IF(RC2<=1*""1/9/1938"",""FLU2"",IF(RC2<=1*""1/9/1948"",""FLU1"",IF(OR(RC12={""Carer"";""Chronic Heart Disease"";""Chronic Liver Disease"";""Chronic Neurological Disease"";""Chronic Renal Disease"";""Chronic Respiratory Disease"";""Diabetes"";""Long-stay residential"";""Immunosuppression"";""Pregnant"";""Stroke / TIA""}),VLOOKUP(RC12,{""Carer"",""ZFCARE"";""Chronic " & _
        "Heart Disease"",""ZFCHD"";""Chronic Liver Disease"",""ZFCLD"";""Chronic Neurological Disease"",""ZFCNS"";""Chronic Renal Disease"",""ZFCRD"";""Chronic Respiratory Disease"",""ZFCRES"";""Diabetes"",""ZFDM"";""Long-stay residential"",""ZFHOME"";""Immunosuppression"",""ZFIMM"";""Pregnant"",""ZFPREG"";""Stroke / TIA"",""ZFSTIA""},2,0),IF(OR(RC10={""PNEUMOPOLY"";""PNEUMOCONJ13""" & _
        "}),VLOOKUP(RC10,{""PNEUMOPOLY"",""PNEU"";""PNEUMOCONJ13"",""PNCHMG""},2,0),IF(AND(RC2<=1*""1/9/2010"",RC2>1*""1/9/2009""),""ZLF3"",IF(AND(RC2<=1*""1/9/2011"",RC2>1*""1/9/2010""),""ZFL2"",IF(RC12="""",""Unidentified"",""N/A"")))))))"


The macro doesn't seem to record the formula properly either, because when it creates a line break it looses bits of the formula, but I think I have resolved this with the code shown above.

I just keep getting the error message now.

Look at this link:

Run-time error using FormulaArray property

The formula have more than 255 characters (>800).

Markmzz
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,589
Members
449,520
Latest member
TBFrieds

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