0

从代码中,根据特定的标准,我试图将公式分配给特定的单元格。查看代码

        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

当 lPriorNum = 1 时,填充 L 的代码可以正常工作。当 lPriorNum 不为 1 时,以下是 sFormula 中的公式,这不起作用。我收到 1004 错误:

=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)

有人告诉我这个公式只适用于 Excel 2010,我正在 2007 年进行测试,但是,2010 年的用户在测试时遇到了同样的错误。这个公式或语法的编写方式可能有什么问题?电子表格上的单元格格式为不带逗号和 2 位小数的数字。我浏览了这里和其他网站的一些帖子,但我认为我的问题可能比我在其他帖子中找到的更具体......

提前感谢您的帮助

4

1 回答 1

1

您需要在 2007 版本中创建一个新工作簿。将公式粘贴=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)到 excel 2007 中没有错误。

将相同的公式粘贴到 97-2003 .xls 文件中会给我太多嵌套级别错误。请注意,转换后的文件会出现相同的问题

于 2012-07-05T19:46:20.830 回答