Excel VBA 宏 - 在一个位置使用单元格的值执行公式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19325849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA Macro - Execute Formula using value of a cell in one location
提问by user2872304
I am new to VBA and was trying to write a macro for some calculations. One of the calculations involves reading in data from a particular location (R2C2 for example) and using a formula to compute a value stored in the adjacent column (R2C3 in this example).
我是 VBA 的新手,并试图为某些计算编写一个宏。其中一项计算涉及从特定位置(例如 R2C2)读取数据,并使用公式计算存储在相邻列中的值(本例中为 R2C3)。
I have this line: ActiveSheet.ActiveSheet.Cells(row_number, Col + 1).Formula = "=ActiveSheet.Cells(row_number, Col).Value + 10"
我有这一行: ActiveSheet.ActiveSheet.Cells(row_number, Col + 1).Formula = "=ActiveSheet.Cells(row_number, Col).Value + 10"
But it does not seem to work and I am not sure why. Everything I have searched for uses Range but I am not sure how to use Range when I am referencing my cells using Row, Column notation instead of A1/B1 notations.
但它似乎不起作用,我不知道为什么。我搜索的所有内容都使用 Range,但是当我使用行、列表示法而不是 A1/B1 表示法引用我的单元格时,我不确定如何使用 Range。
Any help would be great - Thanks
任何帮助都会很棒 - 谢谢
采纳答案by Gary's Student
Here is how to make a formula:
下面是公式的制作方法:
ActiveSheet.Cells(row_number, Col + 1).Formula = "=" & Cells(row_number, Col).Address & "+10"