Hi Vishal 120
I actually tested it this time, I changed the formula so that it made sense on my computer, but the principal is the same. There were a few coding errors ( looping round a negative index doesn't work) this code took 4 secs on my computer see how yours does:
(I put numbers from 1 to 445 in the rows A1 to A445)
Note the R1C1 reference in my equation is used to demonstrate changing the formula for each row (or column), I don't know whether your equation needs this but it is a useful technique to know about.
Sub test()
startTime = Timer
With ThisWorkbook.Sheets("Sheet1")
lLR = Cells(Rows.Count, "A").End(xlUp).Row
End With
inarr = Range("AY59:EX" & lLR)
'assigning the main loading formula
Application.StatusBar = " Automated Planning : Computing ...."
' With Range("AY59:EX" & lLR)
' .Formula = "=IF(OR($AF59="""",$AF59="""",$AJ59=""""),0,IF(AY$58<$AJ59,0,IF(AY$58>=$AJ59,IF(0<($AN59),MIN(($AN59-'SUM(AX59:$AX59)),$AO59,SUMIF(Shadow_Dept_Lines_Sum_Col,$AM59,AY$4:AY$56)-SUMIF($AM$58:$AM58,$AM59,AY$58))))))"
' '.Application.Calculation = xlCalculationAutomatic
' .Value = .Value
' End With
endarray = lLR - 59
' column ex is column 154 column ay is column 59
endcol = 154 - 51
For i = 1 To endarray
For j = 1 To endcol
' inarr(i, j) = "=IF(OR($AF59="""",$AF59="""",$AJ59=""""),0,IF(AY$58<$AJ59,0,IF(AY$58>=$AJ59,IF(0<($AN59),MIN(($AN59-SUM(AX59:$AX59)),$AO59,SUMIF(Shadow_Dept_Lines_Sum_Col,$AM59,AY$4:AY$56)-SUMIF($AM$58:$AM58,$AM59,AY$58))))))"
inarr(i, j) = "=sum(r1c1:r" & i & "c1)"
Next j
Next i
Range("AY59:EX" & lLR).Formula = inarr
MsgBox Timer - startTime & " secs."
End Sub