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
 
You can use this code:

Code:
Sub Test()
    myStr = "=IF(DATEDIF(RC[-2],R1C3,""y"")>=75,""FLU2"",IF(DATEDIF(RC[-2],R1C3,""y"")>=65,""FLU1"",IF(RC[8]="""","
    myStr = myStr & "IF(OR(DATEDIF(RC[-2],R1C3,""y"")={2;3}),""ZFL""&DATEDIF(RC[-2],R1C3,""y""),IF(RC[6]=""PNEUMOCOCONJ13"","
    myStr = myStr & """PNCHMG"",IF(RC[6]=""PNEUMOPOLY"",""PNEU"",""UNIDENTIFIED""))),VLOOKUP(RC12,{""Carer"",""ZFCARE"";"
    myStr = myStr & """Chronic Heart Disease"",""ZFCHD"";""Chronic Liver Disease"",""ZFCLD"";""Chronic Neurological Disease"","
    myStr = myStr & """ZFCNS"";""Chronic Renal Disease"",""ZFCRD"";""Chronic Respiratory Disease"",""ZFCRES"";""Diabetes"",""ZFDM"";"
    myStr = myStr & """Long-stay residential"",""ZFHOME"";""Immunosuppression"",""ZFIMM"";""Pregnant"",""ZFPREG"";""Stroke / TIA"",""ZFSTIA""},2,0))))"
    Range("D2").FormulaR1C1 = myStr
End Sub

Markmzz
 
Last edited:
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Ahhh well not to worry! Wishful thinking. Seems as though Microsoft have improved Excel but not VBA!
I'll just have to reside myself to copy and paste each time instead.

Thanks anyway.
 
Upvote 0
By the time I had pressed reply, you had provded the PERFECT solution, and it only works like a dream.

That's it I not pushing my luck anymore. You have been great thank you so much.

Everything at the click of one button, ITS AMAZING!!!!
 
Upvote 0
By the time I had pressed reply, you had provded the PERFECT solution, and it only works like a dream.

That's it I not pushing my luck anymore. You have been great thank you so much.

Everything at the click of one button, ITS AMAZING!!!!

I'm glad that the code helps and thanks for the feedback.

Markmzz
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

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