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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
these columns go missed off the table:


Excel 2003
JKL
1IMMSTYPESTAGEREASONTXT
2FLU
3FLU
4PNEUMOPOLY
5FLUDiabetes
6FLUChronic Respiratory Disease
7FLUStroke / Tia
8FLUDiabetes
9FLUChronic Renal Disease
10FLUChronic Heart Disease
11FLUChronic Neurological Disease
12FLUChronic Respiratory Disease
13FLUStroke / Tia
14FLU
15FLUSIN1
16FLU
17FLUSIN1Chronic Respiratory Disease
18FLUSIN1Chronic Renal Disease
19PNEUMOCONJ13
Sheet1
 
Upvote 0
I'm not following all of that, but it seems to me that you could create a table with the relevant DOBs in the top row (probably calculated based on today's date), diagnoses/status down the left column, and the vaccine codes (?) in the body of the table. Then do a 2D lookup.
 
Upvote 0
Just to flesh that out a little, you could create a table that has all combinations of ReasonTxt and ImmSType:

A​
B​
C​
D​
E​
F​
G​
1​
As Of Date​
01Sep2013​
2​
Age​
75​
65​
5​
3​
2​
3​
ReasonTxt​
ImmSType​
01Sep1938​
01Sep1948​
01Sep2008​
01Sep2010​
01Sep2011​
4​
FLU
ZFL3​
ZFL2​
5​
FLUSIN
6​
PNEUMOCONJ13
7​
PNEUMOPOLY
8​
CarerFLU
9​
CarerFLUSIN
10​
CarerPNEUMOCONJ13
11​
CarerPNEUMOPOLY
12​
Chronic Heart DiseaseFLU
13​
Chronic Heart DiseaseFLUSIN
14​
Chronic Heart DiseasePNEUMOCONJ13
15​
Chronic Heart DiseasePNEUMOPOLY
16​
Chronic Neurological DiseaseFLU
17​
Chronic Neurological DiseaseFLUSIN
18​
Chronic Neurological DiseasePNEUMOCONJ13
19​
Chronic Neurological DiseasePNEUMOPOLY
20​
Chronic Renal DiseaseFLU
21​
Chronic Renal DiseaseFLUSIN
22​
Chronic Renal DiseasePNEUMOCONJ13
23​
Chronic Renal DiseasePNEUMOPOLY
24​
Chronic Respiratory DiseaseFLU
25​
Chronic Respiratory DiseaseFLUSIN
26​
Chronic Respiratory DiseasePNEUMOCONJ13
27​
Chronic Respiratory DiseasePNEUMOPOLY
28​
DiabetesFLU
29​
DiabetesFLUSIN
30​
DiabetesPNEUMOCONJ13
31​
DiabetesPNEUMOPOLY
32​
PregnantFLU
33​
PregnantFLUSIN
34​
PregnantPNEUMOCONJ13
35​
PregnantPNEUMOPOLY
36​
ResidentFLU
37​
ResidentFLUSIN
38​
ResidentPNEUMOCONJ13
39​
ResidentPNEUMOPOLY
40​
Stroke / TIAFLU
41​
Stroke / TIAFLUSIN
42​
Stroke / TIAPNEUMOCONJ13
43​
Stroke / TIAPNEUMOPOLY
44​
ImmunosuppressedFLU
45​
ImmunosuppressedFLUSIN
46​
ImmunosuppressedPNEUMOCONJ13
47​
ImmunosuppressedPNEUMOPOLY
48​
Chronic Liver DiseaseFLU
49​
Chronic Liver DiseaseFLUSIN
50​
Chronic Liver DiseasePNEUMOCONJ13
51​
Chronic Liver DiseasePNEUMOPOLY
 
Upvote 0
If I understand correctly what you want, this can helps:

Layout

IDDOB01/09/2013Code IMMSTYPESTAGEREASONTXT ReasonCode
20/02/194469y 6m 12dFLU1 FLU CarerZFCARE
02/11/1910102y 9m 30dFLU2 FLU Chronic Heart DiseaseZFCHD
21/09/194270y 11m 11dFLU1 PNEUMOPOLY Chronic Liver DiseaseZFCLD
12/11/197042y 9m 20dZFDM FLU Diabetes Chronic Neurological DiseaseZFCNS
03/08/196350y 0m 29dZFCRES FLU Chronic Respiratory Disease Chronic Renal DiseaseZFCRD
03/11/196250y 9m 29dZFSTIA FLU Stroke / Tia Chronic Respiratory DiseaseZFCRES
17/03/196350y 5m 15dZFDM FLU Diabetes DiabetesZFDM
15/01/196746y 7m 17dZFCRD FLU Chronic Renal Disease Long-stay residentialZFHOME
20/10/196943y 10m 12dZFCHD FLU Chronic Heart Disease ImmunosuppressionZFIMM
05/10/196349y 10m 27dZFCNS FLU Chronic Neurological Disease PregnantZFPREG
13/04/196053y 4m 19dZFCRES FLU Chronic Respiratory Disease Stroke / TIAZFSTIA
09/12/196943y 8m 23dZFSTIA FLU Stroke / Tia Table -> N2:O12
28/10/196943y 10m 4dUnidentified FLU
01/09/20112y 0m 0dZFL2 FLUSIN1
01/09/20103y 0m 0dZLF3 FLU
02/01/20058y 7m 30dZFCRES FLUSIN1Chronic Respiratory Disease
08/01/20058y 7m 24dZFCRD FLUSIN1Chronic Renal Disease
01/08/20112y 1m 0dZFL2 PNEUMOCONJ13
**************************************************************************************************************************************

<colgroup><col width="27" style="width: 20pt; mso-width-source: userset; mso-width-alt: 987;"> <col width="63" style="width: 47pt; mso-width-source: userset; mso-width-alt: 2304;"> <col width="67" style="width: 50pt; mso-width-source: userset; mso-width-alt: 2450;" span="2"> <col width="17" style="width: 13pt; mso-width-source: userset; mso-width-alt: 621;" span="5"> <col width="84" style="width: 63pt; mso-width-source: userset; mso-width-alt: 3072;"> <col width="37" style="width: 28pt; mso-width-source: userset; mso-width-alt: 1353;"> <col width="147" style="width: 110pt; mso-width-source: userset; mso-width-alt: 5376;"> <col width="17" style="width: 13pt; mso-width-source: userset; mso-width-alt: 621;"> <col width="147" style="width: 110pt; mso-width-source: userset; mso-width-alt: 5376;"> <col width="47" style="width: 35pt; mso-width-source: userset; mso-width-alt: 1718;"> <tbody>
</tbody>


Array formula - use Ctrl+Shift+Enter and not only Enter to enter the formula

Code:
D2-> =IF($B2 <= 1*"1/9/1938","FLU2",IF($B2 <= 1*"1/9/1948","FLU1",
IF(OR($L2=$N$2:$N$12),VLOOKUP($L2,$N$2:$O$12,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"))))))


Markmzz
 
Upvote 0
Sorry for not being clearer. I can't change the table as when I have finished checking I have to submit it to another database and it has to be in this exact format.

The table rules work as follows:

If the Date of Birth (DOB) is over 65 it must be either FLU1 or FLU2 no matter what.
FLU1 is if they are 65 to 74 and FLU2 is older than 75 (so this just uses the DOB to work out their age)

The only reason I have added the date 01/09/2013 is because their age must be calculated after that date, i.e. they must be over 65 as at the 1/9/2013.

The next set of codes (ZFCARE, ZFCHD, ZFCLD, ZFCNS, ZFCRD, ZFCRES, ZFDM, ZFHOME, ZFIMM, ZFPREG
ZFSTIA) only apply to those under 65y and each MUST have a risk assigned to them, i.e CHD, Diabetes, etc... shown in column L (and the text is written exactly as shown in my formula, i.e. Carer, Chronic Heart Disease, Chronic Liver Disease, Chronic Neurological Disease, Chronic Renal Disease, Chronic Respiratory Disease, Diabetes, Long-stay residential, Immunosuppression, Pregnant, Stroke / TIA)

ZFL2 is assigned if there age is 2 with no risk code
ZFL3 is assigned if there age is 3 with no risk code
If there is a risk code for 2y and 3y it must show that risk code instead.

Lastly if the IMMTYPE in column J is PNEUMOPOLY (or not FLU) the code is PNEU
and if it shows PNEUMOCONJ13 the code is PNCHMG.

I added the UNIDENTIFIED message for all those that do not meet the exact rules I have explained above, mainly for the under 65ys with no risk code assigned.

I hope that helps. I will be extremly amazed if I can get this to work in one formula, so do let me know if it isn't possible.
 
Upvote 0
I also noticed that if I paste the formula as text it looses virtually all the formula, which I think is what has happened in he last post. I think its the < and > causing the problem
 
Upvote 0
The table I suggested reduces your formula to a simple 2D lookup; it doesn't change anything else. At a glance, Mark's retains the flavor of your formula, and likewise doesn't change anything else.

The reason I suggested a table is that it encapsulates the logic in data rather than a formula.

EDIT:

I think its the < and > causing the problem

< followed by a letter is interpreted as an opening HTML tag. Add a space after it.
 
Last edited:
Upvote 0
I agree with your table and it would make it easier, but I can't change the format of the table as it is required for further submission.
I'm given the data and then just have to manually change each code accordingly. I just thought I might be able to use a formula. I got so far with the IF's but as mentioned in xl2003 I can only use up to 7.

Hopefully Mark will repost his formula using a space as you mentioned so that I may see the whole formula, because he has kept the table format.

Thank you for your suggestion though.
 
Upvote 0
Hopefully Mark will repost his formula using a space as you mentioned so that I may see the whole formula, because he has kept the table format.

Thank you for your suggestion though.

Here you have a big array formula (without the table):

Code:
Use Ctrl+Shift+Enter and not only Enter to enter the formula

=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(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"))))))

PS: I'll try to create another formula for you.

Markmzz
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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