将公式放入单元格时的运行时错误1004

时间:2016-05-18 13:37:13

标签: excel excel-vba runtime-error vba

我刚刚更改了我将代码放入单元格的代码,现在它会调出运行时错误1004(应用程序定义或对象定义错误)。 我的新代码是:

ActiveCell.FormulaR1C1 = _
    "=IF(IsError(VLOOKUP(RC[3],TransactionTypes!C:C[1],2,0)),""MISC"",IF(ISNUMBER(SEARCH(""AX"",(RC[2],2))),""Amex"",VLOOKUP(RC[3],TransactionTypes!C:C[1],2,0)))"

以前工作正常的代码是:

'ActiveCell.FormulaR1C1 = _
    "=IF(IsError(VLOOKUP(RC[3],TransactionTypes!C:C[1],2,0)),""MISC"",IF(LEFT(RC[2],2)=""AX"",""Amex"",VLOOKUP(RC[3],TransactionTypes!C:C[1],2,0)))"

我改变的部分是IF(LEFT(RC [2],2)="" AX"","" Amex"& #34;进入IF(ISNUMBER(搜索("" AX"",(RC [2],2))),"" Amex" "但我不明白为什么这会引起错误。

1 个答案:

答案 0 :(得分:0)

您似乎离开了部分LEFT声明。你需要:

ActiveCell.formular1c1 = _
    "=IF(IsError(VLOOKUP(RC[3],TransactionTypes!C:C[1],2,0)),""MISC"",IF(ISNUMBER(SEARCH(""AX"",RC[2])),""Amex"",VLOOKUP(RC[3],TransactionTypes!C:C[1],2,0)))"