I am trying to a enter a function and i am facing the following problem:

Dim u As Integer

For u = 2 To t - 1 'I calculated the value of variable t earlier in my code

Cells(8, u).Select 'There are two worksheets, Sheet1 and Sheet2. The active sheet is Sheet2

ActiveCell.Formula = "=SUM(--(FREQUENCY(IF(Sheet1!BI2:BI10000=b2,MATCH(Sheet1!q2:q10000,Sheet1!q2:q10000,0)),ROW(Sheet1!q2:q10000)-ROW(Sheet1!q2)+1)>0))"

Next u

The formula itself works fine. However

b2 value is only correct for u=2. I tried to use cells(2,u) instead of b2 but it didnt work.

The same problem occured with the lower limit of the range where i use 100000 instead of the variable k i already have calculated and used erlier.

Do i have a syntax mistake or is something else?

Any help would be great.

Thank you in advance