+ Reply to Thread
Results 1 to 4 of 4

Help with nested IF, No VBA experience

  1. #1
    Registered User
    Join Date
    07-21-2011
    Location
    NY
    MS-Off Ver
    Excel 2011
    Posts
    1

    Help with nested IF, No VBA experience

    I've been working at my job for a couple of weeks now and i've been feeling my way through excel, learning the handy IF function and using it every time I get the chance. I know though, that you cannot nest more than 7 IFs and I used a tip I found on youtube to nest more than 7 ifs by using $ to join groups of 7 ifs. However, I get an error that the formula is invalid,

    The problem is unique because it it requires you to observe the last 3 numbers of a sequence and act on the upcoming number based on the combination of the last 3. (numbers can only be -1, 0 and 1). in short, there are 27 different ways i need excel to be able to act based on the last 3 numbers, therefore 27 nested IFs. Can someone help me with what i cannot accomplish?

    This is the code i have written:
    =IF(AND(X3=-1,X4=-1,X5=-1),Y5*(1+$AA$9*X6),IF(AND(X3=-1,X4=0,X5=-1),Y5*(1+$AB$9*X6),IF(AND(X3=-1,X4=-1,X5=0),Y5*(1+$AC$9*X6),IF(AND(X3=-1,X4=0,X5=0),Y5*(1+$AD$9*X6),IF(AND(X3=-1,X4=1,X5=1),Y5*(1+$AE$9*X6),IF(AND(X3=-1,X4=1,X5=-1),Y5*(1+$AF$9*X6),IF(AND(X3=-1,X4=1,X5=0),Y5*(1+$AG$9*X6),"")))))))&if(and(Y3=-1,Y4=0,Y5=1),Z5*(1+$AH$9*Y6),if(and(Y3=-1,Y4=-1,Y5=1),Z5*(1+$AI$9*Y6),if(and(Y3=0,Y4=-1,Y5=-1),Z5*(1+$AJ$9*Y6),if(and(Y3=0,Y4=0,Y5=-1),Z5*(1+$AK$9*Y6),if(and(Y3=0,Y4=-1,Y5=0),Z5*(1+$AL$9*Y6),if(and(Y3=0,Y4=0,Y5=0),Z5*(1+$AM$9*Y6),if(and(Y3=0,Y4=1,Y5=1),Z5*(1+$AN$9*Y6))))))))&if(and(Y3=0,Y4=1,Y5=-1),Z5*(1+$AO$9*Y6),if(and(Y3=0,Y4=1,Y5=0),Z5*(1+$AP$9*Y6),if(and(Y3=0,Y4=0,Y5=1),Z5*(1+$AQ$9*Y6),if(and(Y3=0,Y4=-1,Y5=1),Z5*(1+$AR$9*Y6),if(and(Y3=1,Y4=-1,Y5=-1),Z5*(1+$AS$9*Y6),if(and(Y3=1,Y4=0,Y5=-1),Z5*(1+$AT$9*Y6),if(and(Y3=1,Y4=-1,Y5=0),Z5*(1+$AU$9*Y6)))))))))&IF(and(Y3=1,Y4=0,Y5=0),Z5*(1+$AV$9*Y6),if(and(Y3=1,Y4=1,Y5=1),Z5*(1+$AW$9*Y6),if(and(Y3=1,Y4=1,Y5=-1),Z5*(1+$AX$9*Y6),if(and(Y3=1,Y4=1,Y5=0),Z5*(1+$AY$9*Y6),if(and(Y3=1,Y4=0,Y5=1),Z5*(1+$AZ$9*Y6),if(and(Y3=1,Y4=-1,Y5=1),Z5*(1+$BA$9*Y6)))))))*1

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Help with nested IF, No VBA experience

    Try something like

    =CHOOSE(4*X3+2*X4+X5,....)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    07-14-2011
    Location
    Lohr, Germany
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: Help with nested IF, No VBA experience

    Depends whether the switching from testing the X column in your first IF block to testing the Y column in the rest of the formula is by design or a typo.
    In case the results are always like this Z5*(1+$AP$9*Y6) then you could do the following:
    make a list of your choices in a separate range having in the first column the concatenated numbers and in the second your constants (like the value in $AP$9 in the example above.).
    Would then look like this
    -10-1 Value1
    -1-10 Value2
    .... and so on for 27 rows
    Then you could simplify your formula like this:
    = Z5*(1+VLOOKUP(text(Y3&Y4&Y5,"0"),$A1:$B27;2;false) *Y6)
    Assuming your constants are in $A1:$B27, but you can place them everywhere, even in another sheet. I prefer to assign a range name for easier reading.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Help with nested IF, No VBA experience

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this, then please add links to any and all cross-posts in your first post here.
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1