More than 7 (almost unlimited) nested ifs YES it's possible

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Yes it is possible to nest more than 7 Ifs. And it's practically unlimited, I've gone as far as 26. (just the alphabet)

1st, must give credit where it's due. Fitzhay showed this to me in this post

http://www.mrexcel.com/board2/viewtopic.php?t=250235&highlight=

Don't kow if it was his original idea or not, but that's where I got it.

How? - Concatenate

simply write your basic 7 nested if formula
Code:
=IF(A1="a",1,IF(A1="b",2,IF(A1="c",3,IF(A1="d",4,IF(A1="e",5,IF(A1="f",6,IF(A1="g",7,"")))))))

make sure to use "" in the False section of the 7th if.

then ADD another 7 nested if formula to the end of that, sepreated by &

Code:
=IF(A1="a",1,IF(A1="b",2,IF(A1="c",3,IF(A1="d",4,IF(A1="e",5,IF(A1="f",6,IF(A1="g",7,"")))))))&IF(A1="h",8,IF(A1="i",9,IF(A1="j",10,IF(A1="k",11,IF(A1="l",12,IF(A1="m",13,IF(A1="n",14,"")))))))

IMPORTANT !!!!!!!
This is technically 2 nested if statements Joined together into 1 text string by concatenate (&). It is important for you to recognize where each nested if statement begins and ends. You MUST put "" in the LAST (furthest to right) False section of EACH Nested IF Statement.
for example, in the example formula I gave, it ended like this
IF(A1="n",14)))))))
and if I typed B in A1, it will display result of 1st nested if&"FALSE" or
2FALSE

The only problem I see with this is Concatenate forces the result as text, which can be problematic if you need numbers for other dependant formulas.

But easily resolved by adding -- to the beginning

Code:
--(=IF(A1="a",1,IF(A1="b",2,IF(A1="c",3,IF(A1="d",4,IF(A1="e",5,IF(A1="f",6,IF(A1="g",7,"")))))))&IF(A1="h",8,IF(A1="i",9,IF(A1="j",10,IF(A1="k",11,IF(A1="l",12,IF(A1="m",13,IF(A1="n",14,""))))))))


Just awesome !!
 
I might be misinterpreting the issue, but


= if (iserror(match(a1,{"v1","v2",..,"vn"},0),"false",match(a1,{"v1","v2",..."vn"},0))

will compare a1 against a lot of constants, returning a different value depending on which constant is present.

Combined with CHOOSE, would this be relevant to the issue at hand?
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Yes, I'll totally agree there are more efficient ways to accomplish whatever you're doing with nested ifs. But I made this post strictly as an answer that YES, you can nest more than 7 Ifs. As I've watched, read and responded in this forum, How to (or need to) get around the 7 nested if limit is a very common issue presented.

I present this post simply as an easy method to nest more than 7 ifs. Once someone understands how to do nested ifs, it's very easy to understand how to make more than 7. By Simply adding the &. Some may not understand the Choose/Match or Lookup methods. I personally am barely getting a grasp on those myself, so the nested if's are easier to write/understand.
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,020
Members
449,480
Latest member
yesitisasport

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