将其转换为 vba 时出现 iferror 错误

iferror error when translate it to vba

我正在尝试使用 vba

来模仿 iferror 公式
=IFERROR(VLOOKUP(C4,E:E,1,FALSE),"Test")

当我尝试编写完全相同的代码时,错误指向“"Test"” 有没有办法不使用“”?

ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(R[-1]C[-4],C[-2],1,FALSE)," & ""Test"" & ")"

提前致谢!

因为我不知道在这些情况下要放多少 ",所以我更喜欢使用 ChrW(34)

这应该很容易工作:

    ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(R[-1]C[-4],C[-2],1,FALSE)," & _
        ChrW(34) & "Test" & ChrW(34) & ")"

如果您对 ChrW 或 AsciiW 有疑问:

MsgBox AscW("""")
MsgBox ChrW(34)