Excel - maximum nested IFs

Asked By Opal
09-Feb-10 03:15 PM
Help.... I understand that Excel only allows for 7
nested IF statements.... I have 7, but the following
responds with #VALUE! for the last 2 items in
my function:

=IF(C29942="1A",VLOOKUP(H29942,DSVLookup!$D$2:$G$17,2,FALSE),
IF(C29942="2A",VLOOKUP(H29942,DSVLookup!$D$18:$G$37,2,FALSE),
IF(C29942="3C",VLOOKUP(H29942,DSVLookup!$D$38:$G$53,2,FALSE),
IF(C29942="3D",VLOOKUP(H29942,DSVLookup!$D$54:$G$64,2,FALSE),
IF(C29942="4A",VLOOKUP(H29942,DSVLookup!$D$65:$G$77,2,FALSE),
IF(C29942="5TR1",VLOOKUP(DSVLookup!$D$78:$G$94,2,FALSE),
IF(C29942="5TR2",VLOOKUP(DSVLookup!$D$95:$G$122,2,FALSE),"")))))))

It works fine on 1A, 2A, 3C, 3D and 4A, but I get that error for the
last two.
What am I doing wrong?
Microsoft Excel
(1)
Excel
(1)
INDIRECT
(1)
VLOOKUP
(1)
CHOOSE
(1)
MATCH
(1)
ISNA
(1)
DSVLookup
(1)
  Niek Otten replied to Opal
09-Feb-10 03:20 PM
You omitted "H29942" in the last two

--
Kind regards,

Niek Otten
Microsoft MVP - Excel
  Opal replied to Niek Otten
09-Feb-10 03:32 PM
D'oh....

Thank you....been looking at it too long
  Joe User replied to Niek Otten
09-Feb-10 03:34 PM
Great!  You spotted it before I could.  I am multitasking at the moment.

One thing:  can we help her eliminate the IF nesting?

it is not necessary.  But it might be helpful to her in the long-run.

There seems to a pattern in the ranges.  I am thinking of using INDIRECT and
CHOOSE within the VLOOKUP.  If we can avoid volatile functions like
INDIRECT, so much the better.  It would take me some time to work that out,
which I do not have.  But I will bet you can do this in your sleep.


----- original message -----
  Niek Otten replied to Joe User
09-Feb-10 04:43 PM
Since the reference to the table is 4 columns, while only two are used, I
assume that it is some existing table which cannot be changed.

What I would do is add two columns in front of that table.
First column (B): Rows 2-17 contain "1A", rows 18-37 contain "2A", etc.
Second column: (C) =B2&D2, fill down to row 53

Lookup Formula: =VLOOKUP(C29942&H29942,DSVLookup!$C$2:$E$53,3,FALSE)

No provision yet for #NA, but that is simple;
=IF(ISNA(YourFormula),"",YourFormula). In Excel2007:
=IFERROR(YourFormula,"")

Also, if you had to insert columns because there was no empty spaceto the
left of the table, you will have to adapt the column letters.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel
  T. Valko replied to Joe User
09-Feb-10 05:10 PM
Using a bunch of defined names we can reduce that considerably.

Defined names:

Codes
Refers to:
={"1A","2A","3C","3D","4A","5TR1","5TR2"}

1A
Refers to:
=DSVLookup!$D$2:$G$17

2A
Refers to:
=DSVLookup!$D$18:$G$37

3C
Refers to:
=DSVLookup!$D$38:$G$53

3D
Refers to:
=DSVLookup!$D$54:$G$64

4A
Refers to:
=DSVLookup!$D$65:$G$77

5TR1
Refers to:
=DSVLookup!$D$78:$G$94

5TR2
Refers to:
=DSVLookup!$D$95:$G$122

Then:

=IF(OR(C29942=Codes),VLOOKUP(H29942,CHOOSE(MATCH(C29942,Codes,0),1A,2A,3C,3D,4A,5TR1,5TR2),2,0),"")

--
Biff
Microsoft Excel MVP
  T. Valko replied to T. Valko
09-Feb-10 05:20 PM
Well Doh!

Disregard all those names for the named ranges. They're invalid names!!!

If you wanted to name them something like Rng1A, Rng2A, Rng3C, etc. Then:

=IF(OR(C29942=Codes),VLOOKUP(H29942,CHOOSE(MATCH(C29942,Codes,0),Rng1A,Rng2A,Rng3C,Rng3D,Rng4A,Rng5TR1,Rng5TR2),2,0),"")

--
Biff
Microsoft Excel MVP
Create New Account
help
Indirect Excel i am referencing a worksheet using the indirect function. excel is automatically adding the active worksheet name to the formula which returns #REF. how can i how can i stop it from automatically adding the sheet name? thanks, Excel Worksheet Discussions Microsoft Excel (1) Worksheet (1 INDIRECT (1) Workseet (1) Assume we cannot see your worksheet and formula you are attempting to
How do I STOP this;;;;; Excel Excel 2007 How do I stop Excel from asking me to save changes when only the cursor has been moved? Previous versions did not do this. It is quite annoying. J Excel Discussions Microsoft Excel (1) Excel 2007 (1) RANDBETWEEN (1 INDIRECT (1) OFFSET (1) INDEX (1) RAND (1) INFO (1) Does your file contain formulas that
excel: count uppercase letters in a cell Excel excel: how to count uppercase letters in a cell Excel Worksheet Discussions Windows XP (1) Microsoft Excel (1) SUBSTITUTE (1) SUMPRODUCT (1) FREQUENCY (1) INDIRECT (1) COLUMN (1) LOWER (1) One way, = SUMPRODUCT(LEN(A1)-LEN(SUBSTITUTE(A1, {"A";"B C";"D";"E";"F"; Another one: = SUMPRODUCT(LEN(A1)-LEN(SUBSTITUTE(A1, CHAR(ROW(INDIRECT("65:90"))), ""))) - - Biff Microsoft Excel MVP If we know that no text will be longer
alpha numeric data validation for excel Excel I want to use a non vb formula in data validation for an excel formula to make the user enter the first 2 characters of a field as UPPERCASE i.e. AB12345 - the format is always the same 2 letters 5 numbers. Any ideas? Excel Worksheet Discussions Microsoft Excel (1) SUBSTITUTE (1) SUMPRODUCT (1) ISNUMBER (1) INDIRECT (1) PRODUCT (1) COUNT (1) UPPER (1) With the validated cell being A2: = 3DPRODUCT(- -(CODE MID(A2, ROW(INDIRECT("1:2")), 1))> = 3D65))*PRODUCT(- -(CODE (MID(A2, ROW(INDIRECT("1:2")), 1))< = 3D90))*PRODUCT
Conflict with Valid Range Reference Error in Microsoft Excel 2007 Excel Hi, While converting the Macros enabled Microsoft Excel 2003 to Microsoft Excel 2007 format, I am getting the following Conflict with Valid Range Reference Error. After clicking on the Ok \ OK to All buttons the VBA code in the Excel is not working as it is expected to. The following is the Error message. invalid