我最近尝试更改VBA代码
Range("J2:J" & Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = _
"=INDEX(Accounts!R2C3:R491C3,MATCH(RC[-8],Accounts!R2C2:R491C2,0))"
到
Range("J2:J" & Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = _
"=IFERROR(INDEX(Accounts!R2C3:R491C3,MATCH(RC[-8],Accounts!R2C2:R491C2,0)),"")"
但后面的代码收到错误。我有什么简单的遗失吗?
更新:使用以下代码发生同样的错误:
Range("J2:J" & Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = _
"=IFERROR((=INDEX(Accounts!R2C3:R" & lastrow & "C3,MATCH(RC[-8],Accounts!R2C2:R" & lastrow & "C2,0)),"""")"
在上文中,lastrow = Cells(Rows.Count, "A").End(xlUp).Row
答案 0 :(得分:1)
您应该在公式中使用双引号:
Range("J2:J" & Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = _
"=IFERROR(INDEX(Accounts!R2C3:R491C3,MATCH(RC[-8],Accounts!R2C2:R491C2,0)),"""")"