为什么我不能在VBA中运行.formulaR1C1?

时间:2014-11-24 23:54:27

标签: excel vba excel-vba

我有一个模块,我成功运行了以下代码:

Range("D1").Select
    ActiveCell.FormulaR1C1 = _
        "=+SUM('Monthly Report Export'!R[8]C[1]:R[4998]C[1],'Monthly Report Export'!R[5000]C[1]:R[9998]C[1],'Monthly Report Export'!R[10000]C[1]:R[14998]C[1],'Monthly Report Export'!R[15000]C[1]:R[19998]C[1])"

当我运行此代码时,我得到“运行时错误1004”对象定义错误....

Range("D42").Select
    ActiveCell.FormulaR1C1 = _
        "=+IF(VLOOKUP(RC[-1],'Rep Aux'!R30C4:R64C5,2,0)=MONTH(Master!R10C4),0,SUMIFS('Monthly Report Export'!R9C5:R4999C5,'Monthly Report Export'!R9C9:R4999C9,""Si"",'Monthly Report Export'!R9C4:R4999C4,"">""&'Rep Aux'!R30C2,'Monthly Report Export'!R9C4:R4999C4,""<""&'Rep Aux'!R31C2)*0.05+SUMIFS('Monthly Report Export'!R5000C5:R9999C5,'Monthly Report Export'!R5000C9:R9999C9," & _
        "Monthly Report Export'!R5000C4:R9999C4,"">""&'Rep Aux'!R30C2,'Monthly Report Export'!R5000C4:R9999C4,""<""&'Rep Aux'!R31C2)*0.025+SUMIFS('Monthly Report Export'!R10000C5:R14999C5,'Monthly Report Export'!R10000C9:R14999C9,""Si"",'Monthly Report Export'!R10000C4:R14999C4,"">""&'Rep Aux'!R30C2,'Monthly Report Export'!R10000C4:R14999C4,""<""&'Rep Aux'!R31C2)*0.06+SUMIFS" & _
        " Report Export'!R15000C5:R19999C5,'Monthly Report Export'!R15000C9:R19999C9,""Si"",'Monthly Report Export'!R15000C4:R19999C4,"">""&'Rep Aux'!R30C2,'Monthly Report Export'!R15000C4:R19999C4,""<""&'Rep Aux'!R31C2)*0.1+SUMIFS('Monthly Report Export'!R20000C5:R24999C5,'Monthly Report Export'!R20000C9:R24999C9,""Si"",'Monthly Report Export'!R20000C4:R24999C4,"">""&'Rep A" & _
        ",'Monthly Report Export'!R20000C4:R24999C4,""<""&'Rep Aux'!R31C2)*0.01)"

这是一个庞大的公式,我不像我在excel那样精通vba,所以我在标准A1中编写公式,然后使用记录功能将公式转换为VBA友好的R1C1代码

为什么我不能执行上述操作?第一个公式工作正常,第二个公式没有。我试过用一个标准把它简化为一个sumif而没有任何东西。老实说,我不知道出了什么问题。

谢谢!

0 个答案:

没有答案