-3

My function is

=IF(C2="A",IF(D2=1,"",IF(D2=ODD(D2),D2*3+1,D2/2)),IF(C2="B",IF(D2=1,"",IF(D2=ODD(D2),D2*3+1,D2/2)))IF(C2="C",IF(D2=1,"",IF(D2=ODD(D2),D2*3+1,D2/2)))IF(C2="D",IF(D2=1,"",IF(D2=ODD(D2),D2*3+1,D2/2)),IF(c2=1,"",IF(c2=ODD(c2),c2*3+1,c2/2)))))

and it is giving me a parse error. I have tried rewriting it a couple of times but it just isn't working. Can someone help me figure out what is wrong with it?

  • You're missing ","s before IF c2=c and various places. Please learn syntax of Nesting IF and try again – TheMaster Oct 5 '17 at 12:39
  • Basic troubleshooting: Begin with the smallest piece and add pieces until you find where the error is. – ale Oct 5 '17 at 13:14
  • What does the error say exactly? – freginold Oct 5 '17 at 13:17
  • Kind of messy formula with some errors in it, ones that are not just syntax. You can try =IF(AND(ISNUMBER(SEARCH(C2,"ABCD")),ISODD(D2)),D2*3+1,IF(AND(ISNUMBER(SEARCH(C2,"ABCD")),ISEVEN(D2)),D2/2,IF(AND(C2=1,ISODD(C2)),C2*3+1,IF(AND(C2=1,ISEVEN(C2)),C2/2,FALSE)))) – Xzila Oct 5 '17 at 20:13
1

It's easy to see where you're missing commas if you "explode" your nested functions:

IF(
  boolean expression,
  if true,
  if false
)

So for your function:

IF(
  C2="A",
  IF(
    D2=1,
    "",
    IF(
      D2=ODD(D2),
      D2*3+1,D2/2
    )
  ),
  IF(
    C2="B",
    IF(
      D2=1,
      "",
      IF(
        D2=ODD(D2),
        D2*3+1,
        D2/2
      )
    )
  )
  IF(
    C2="C",
    IF(
      D2=1,
      "",
      IF(
        D2=ODD(D2),
        D2*3+1,
        D2/2
      )
    )
  )
  IF(
    C2="D",
    IF(
      D2=1,
      "",
      IF(
        D2=ODD(D2),
        D2*3+1,
        D2/2
      )
     ),
     IF(
       c2=1,
       "",
       IF(
         c2=ODD(c2),
         c2*3+1,
         c2/2
       )
     )
   )
 )
)

You should be able to see where you're missing some commas. You also seem to have some mismatched parentheses. A tool that can help you match up braces is helpful. (I used Notepad++.)

I'd suggest, for troubleshooting a complex set of nested IFs like this, you use some "helper" cells to hold formulas, or even their own if blocks, to keep things simpler. Then, if you really want to, you can replace the references to those cells with their formulas and re-create the IF monster. It might be easier to leave them in place, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.