1

I am trying write a CountIF formula that uses a dynamic criteria to count from a fixed range. Below is the code I was trying to make work:

Dim Flow As String

j = 5
For i = 1 To 13
    Flow = Cells(2, j)
    Cells(6, j).Formula = "=COUNTIF($E50:$E100,Flow)"
    j = j + 2     
Next i

The results pastes =COUNTIF($E50:$E100,Flow) in the targeted cells instead of =Countif($E50:$E100,E2), =Countif($E50:$E100,G2), and so on.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73

2 Answers2

2

Thank You Johanness. Because the lookup criteria had to be string. I just had to make a slight tweak.

Cells(6, j).Formula = "=COUNTIF($E50:$E100,""" & Flow & """)"

This seems to do it. Cheers! Appreciate the help

1

try

Cells(6, j).Formula = "=COUNTIF($E50:$E100," & Flow & ")"