I am writing a code in VBA where I'm trying to fill some cells with a formula while the cell right next to it is different from "". However, my loop never ends and when I interrupt it, it shows me that it's running (or stucked) at the addition of the iterator (sorry for the bad english).
Here's what I wrote so far:
While Cells(i, 4) <> ""
Cells(i, 5).FormulaR1C1 = "=IFERROR(IF(RC[-3]=R[-1]C[-3],"""",IF(AND(RC[-3]=R[1]C[-3],RC[-3]=R[2]C[-3],RC[-3]=R[3]C[-3],RC[-3]=R[4]C[-3],RC[-3]=R[5]C[-3],RC[-3]=R[6]C[-3]),SUMPRODUCT(RC[-2]:R[4]C[-2],RC[-1]:R[6]C[-1])/SUM(RC[-2]:R[6]C[-2]),IF(AND(RC[-3]=R[1]C[-3],RC[-3]=R[2]C[-3],RC[-3]=R[3]C[-3],RC[-3]=R[4]C[-3],RC[-3]=R[5]C[-3]),SUMPRODUCT(RC[-2]:R[4]C[-2],RC[-1]:R[5]C[-1])/SUM(RC[-2]:R[5]C" & _
"[-2]),IF(AND(RC[-3]=R[1]C[-3],RC[-3]=R[2]C[-3],RC[-3]=R[3]C[-3],RC[-3]=R[4]C[-3]),SUMPRODUCT(RC[-2]:R[4]C[-2],RC[-1]:R[4]C[-1])/SUM(RC[-2]:R[4]C[-2]),IF(AND(RC[-3]=R[1]C[-3],RC[-3]=R[2]C[-3],RC[-3]=R[3]C[-3]),SUMPRODUCT(RC[-2]:R[3]C[-2],RC[-1]:R[3]C[-1])/SUM(RC[-2]:R[3]C[-2]),IF(AND(RC[-3]=R[1]C[-3],RC[-3]=R[2]C[-3]),SUMPRODUCT(RC[-2]:R[2]C[-2],RC[-1]:R[2]C[-1])/SUM" & _
"(RC[-2]:R[2]C[-2]),IF(RC[-3]=R[1]C[-3],SUMPRODUCT(RC[-2]:R[1]C[-2],RC[-1]:R[1]C[-1])/SUM(RC[-2]:R[1]C[-2]),RC[-1]))))))),"""")" & _
""
i = i + 1
Wend
The formula is working and I am getting the result I expected. However, the application never ends running until e press esc twice. Then when I debug it, the application shows me the "i = i + 1" in yellow.
How can I fix it?