Hi,
With this code I get the expected result ...
I used an array to avoid delays with 500,000 rows to update.Code:Sub Test_A() Dim Riga As Long Dim Dn As Long Dim rng As Variant Dim Num As Integer Num = Cells(2, 12) 'Value = 10 Dn = Range("C" & Rows.Count).End(xlUp).Row rng = Range("IV1:IV" & Dn) 'Range without any data For Riga = Num + 1 To UBound(rng) rng(Riga, 1) = Evaluate("SUM(C" & Riga - Num + 1 & ":" & "C" & Riga & ")/L2") '=SUM(C2:C11)/L2 Next Range("O1:O" & Dn) = rng End Sub
Definitely worth a general overhaul to improve the code.
Bookmarks