VBA设置单元格的公式 [英] VBA setting the formula for a cell

查看:150
本文介绍了VBA设置单元格的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用(动态创建的)工作表名称和固定的单元格地址设置单元格的公式。我使用以下行,但似乎无法使其正常工作:

I'm trying to set the formula for a cell using a (dynamically created) sheet name and a fixed cell address. I'm using the following line but can't seem to get it working:

"=" & strProjectName & "!" & Cells(2, 7).Address

任何关于为什么这不工作或一个prod非常感谢。

Any advice on why this isn't working or a prod in the right direction would be greatly appreciated.

提前感谢

推荐答案

不知道在你的情况下什么不起作用,但下面的代码将把一个公式放到单元格A1中,该公式将检索单元格G2中的值。

Not sure what isn't working in your case, but the following code will put a formula into cell A1 that will retrieve the value in the cell G2.

strProjectName = "Sheet1"
Cells(1, 1).Formula = "=" & strProjectName & "!" & Cells(2, 7).Address

工作簿和工作表 strProjectName 引用必须在此公式放置时存在。 Excel会立即尝试评估公式。您可以通过关闭自动重新计算直到工作簿确实存在来阻止这种情况发生。

The workbook and worksheet that strProjectName references must exist at the time that this formula is placed. Excel will immediately try to evaluate the formula. You might be able to stop that from happening by turning off automatic recalculation until the workbook does exist.

这篇关于VBA设置单元格的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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