VBA Variable inside formula

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

Upvotes: 0

Views: 10712

Answers (1)

Sorceri
Sorceri

Reputation: 8053

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])"

Upvotes: 2

Related Questions