Excel宏公式在公式中添加引号,导致vlookup不起作用 [英] Excel macro formula adding quotes in formula causing vlookup to not work

查看:483
本文介绍了Excel宏公式在公式中添加引号,导致vlookup不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向单元格添加公式。宏是在单元格范围附加引号,导致单元格返回#name错误。

I am trying to add a formula to a cell. The macro is adding quotations around the cell range, which causes the cell to return the #name error.

这是宏中的代码

Cells(1, 4).FormulaR1C1 = "=VLOOKUP(RC[-2],Contracts!A7:D30,3,FALSE)"

这是代码在执行宏后在Excel中返回的代码。

This is what the code returns in Excel after executing the macro.

=VLOOKUP(B4,Contracts!'A7':'D30',3,FALSE) 

请注意,在删除单元格A7和D30周围的引号后,#name错误消失,该公式起作用。

Note that #name error disappears and the formula works, after I remove the quotations around the cell A7 and D30.

推荐答案

您不能在同一个公式中混合RC和A1风格的引用。选择一个并坚持下去。

You cannot mix RC and A1 style references in the same formula. Pick one and stick to it.

"=VLOOKUP(RC[-2],Contracts!R7C1:R30C4,3,FALSE)"

将工作

这篇关于Excel宏公式在公式中添加引号,导致vlookup不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆