vba 公式内的VBA变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25650605/
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-12 04:27:00  来源:igfitidea点击:

VBA Variable inside formula

excelexcel-vbaexcel-formulavba

提问by Patricio Torres Serrano

I have the following code

我有以下代码

 ActiveCell.FormulaR1C1 = "=COUNTIF(R[-54]C[-14]:R[-54]C[90],RC[-4])"

I want to replace 90 with a variable "total", I tried this but didn't work:

我想用变量“total”替换 90,我试过这个但没有用:

Dim total  as Integer
total=Inputbox("Enter a number")
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-54]C[-14]:R[-54]C[ " & total & " ],RC[-4])"

Ty for your help

你的帮助

回答by Sorceri

you need to remove the spaces in the bracket.

您需要删除括号中的空格。

Dim total  as Integer
total=Inputbox("Enter a number")
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-54]C[-14]:R[-54]C[" & total & "],RC[-4])"