VBA- 范围内的变量,在公式内
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10098802/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:48:54 来源:igfitidea点击:
VBA- variable in a range, inside a formula
提问by user1115535
I have the following code, to calculate the max in a range of cells:
我有以下代码,用于计算一系列单元格中的最大值:
Range("E3").Select
ActiveCell.FormulaR1C1 = "=MAX(RC[-3]:R[50]C[-3])"
How can I replace 50 with a variable in my code?
如何用代码中的变量替换 50?
Thanks for your help!
谢谢你的帮助!
回答by andydev
Have you tried this:
你有没有试过这个:
Dim sVal as String
sVal = "50"
ActiveCell.FormulaR1C1 = "=MAX(RC[-3]:R[" & sVal & " ]C[-3])"
回答by Marc
Something like this:
像这样的东西:
Dim somevar as Integer
somevar = 50
ActiveCell.FormulaR1C1 = "=MAX(RC[-3]:R[" + somevar + "]C[-3])"

