VBA Variable inside formula

2020-05-06 14:10发布

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:

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

1条回答
该账号已被封号
2楼-- · 2020-05-06 15:15

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])"
查看更多
登录 后发表回答