From within code, based on particular criteria, I am trying to assign a formula to a particular cell. See code
For l = 8 To lEND
lPriorNum = .Range("N" & l)
If lPriorNum = 1 Then
sFormula = "=ROUND(IF(AND(N" & l & "=1,K" & l & "=0),O" & l & _
"/100*M" & l & ",(IF(AND(N" & l & "=1,K" & l & "<>0,K" & l & _
"<M" & l & "),K" & l & ",M" & l & "))),2)"
Else
sFormula = "=ROUND(IF(P" & l & "=0,0,(IF(AND(N" & l + 1 & _
"<>1,K" & l + 1 & "<>0,M" & l + 1 & ">R" & l + 1 & _
"),K" & l + 1 & ",(IF(AND(N" & l + 1 & "<>1,K" & l + 1 & _
"<>0,P" & l & ">0,P" & l & "<K" & l + 1 & "),+P" & l & _
",(IF(AND(N" & l + 1 & "<>1,K" & l + 1 & "=0,P" & l & _
"<=0),0,(IF(O" & l + 1 & "/100*SUM(M" & l + 1 & "-L" & l & _
")>M" & l + 1 & ",0,(IF(O" & l + 1 & "/100*SUM(M" & l + 1 & _
"-R" & l & ")<M" & l + 1 & ",O" & l + 1 & "/100*SUM(M" & l + 1 & _
"-R" & l & "),(IF(M" & l + 1 & "<=R" & l + 1 & ",IF(P" & l + 1 & _
"-K" & l + 1 & "<0,0,+M" & l + 1 & "-K" & l + 1 & ")))))))))))))),2)"
End If
.Range("L" & l).Select
Selection.NumberFormat = "0.00"
ActiveCell.Formula = sFormula
Selection.NumberFormat = "0.00"
' Total Payout Available
sFormula = Range("Tot_Pay_Avail").Formula
.Range("P" & l).Select
Selection.NumberFormat = "0.00"
ActiveCell.Formula = sFormula
Selection.NumberFormat = "0.00"
' Final Dist Running Bal
sFormula = Range("Final_Dist_RB").Formula
.Range("Q" & l).Select
Selection.NumberFormat = "0.00"
ActiveCell.Formula = sFormula
Selection.NumberFormat = "0.00"
sFormula = Range("Payout_Amt_Sum").Formula
.Range("R" & l).Select
Selection.NumberFormat = "0.00"
ActiveCell.Formula = sFormula
Selection.NumberFormat = "0.00"
sFormula = vbNullString
Next l
When the lPriorNum = 1, the code to populate L whatever works fine. When the lPriorNum is not 1, the following is the formula that is in sFormula and this does not work. I get the 1004 error:
=ROUND(IF(P9=0,0,(IF(AND(N10<>1,K10<>0,M10>R10),K10,(IF(AND(N10<>1,K10<>0,P9>0,P91,K10=0,P9<=0),0,(IF(O10/100*SUM(M10-L9)>M10,0,(IF(O10/100*SUM(M10-R9)
I’ve been told this formula as it’s written will only work in Excel 2010 and I am testing in 2007, however, 2010 users are getting the same error when they test this. What might be the issue with this formula or the way the syntax is written? The cell on the spreadsheet is formatted as number with no commas and 2 decimals. I’ve looked through some of the postings here and other websites but I think my question might be more specific than I might find in other postings…
Thanks in advance for any help
you need to create a new workbook in the 2007 version. Pasting the formula
=ROUND(IF(P9=0,0,(IF(AND(N10<>1,K10<>0,M10>R10),K10,(IF(AND(N10<>1,K10<>0,P9>0,P9<K10),+P9,(IF(AND(N10<>1,K10=0,P9<=0),0,(IF(O10/100*SUM(M10-L9)>M10,0,(IF(O10/100*SUM(M10-R9)<M10,O10/100*SUM(M10-R9),(IF(M10<=R10,IF(P10-K10<0,0,M10-K10)))))))))))))),2)into excel 2007 works with no errors.Pasting the same formula into a 97-2003 .xls file gives me the Too many levels of nesting error. note that a converted file will give the same issues