Results 1 to 20 of 68

Thread: Advice needed to speed this code.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    I think I know why your code is so slow, the With range statement means the code accesses the spreadsheet multiple times, the way to do it is to write all the equations into an array and then write the array to the spreadsheet in one go . I just tired this code and it was a factor of 50 times faster than yours.

    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 = 59 - lLR
          For i = 1 To endarray
            inarr(i, 1) = "=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))))))"
          Next i
           Range("AY59:EX" & lLR) = inarr
    Last edited by SamT; 05-20-2016 at 04:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •