-
I'm going to be lazy and not go down the route of making all the calculations in-memory. The formula is much simpler than the last exercise and doesn't depend on other values in the same range, so there'll be no real speed advantage over the solutions below.
The first solution is the slowest completing 170 times faster than your routine:
[vba]Sub Still_To_Load_MIns1()
StartTime = Timer
'the following loop is necessary since .end and specialcells were not reliable as there is something in apparently blank cells:
Application.Calculation = xlCalculationManual
For Each cll In Range("Shadow_KS_Modules_col").Cells
If cll.Value = "" Then
Set KSModulesRng = Range(Range("Shadow_KS_Modules_col").Cells(1), cll.Offset(-1))
If KSModulesRng.Row < Range("Shadow_KS_Modules_col").Row Then
MsgBox "No modules"
Exit Sub
End If
Exit For
End If
Next cll
'KSModulesRng is now the range of modules in column AD
Range("Shadow_KS_Capacity_Area").ClearContents
With Intersect(Range("shadow_KS_Capacity_Area"), KSModulesRng.EntireRow)
.FormulaR1C1 = _
"=shadow_k_mins!RC[23]-SUMIF(shadow_k_mins!R35C18:R1544C18,shadow_k_mins!RC30,shadow_k_mins!R35C[23]:R1544C[23])"
Application.Calculation = xlCalculationAutomatic
.Value = .Value
End With
MsgBox Timer - StartTime & " secs."
End Sub
[/vba] The above is also the safest of the three in case there is something wrong/missing in AD3:AD32.
The second solution runs 220 times as fast as yours:
[vba]Sub Still_To_Load_MIns2()
StartTime = Timer
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Range("Shadow_KS_Capacity_Area").ClearContents
With Intersect(Range("shadow_KS_Capacity_Area"), Range("Shadow_KS_Modules_col").SpecialCells(xlCellTypeConstants, 19).EntireRow)
.FormulaR1C1 = "=shadow_k_mins!RC[23]-SUMIF(shadow_k_mins!R35C18:R1544C18,shadow_k_mins!RC30,shadow_k_mins!R35C[23]:R1544C[23])"
Application.Calculation = xlCalculationAutomatic
.Value = .Value
End With
Application.ScreenUpdating = True
MsgBox Timer - StartTime & " secs."
End Sub[/vba]
and the third solution 230 times as fast:
[vba]Sub Still_To_Load_MIns3()
StartTime = Timer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set KSModulesRng = Range(Range("Shadow_KS_Modules_col").Cells(1), Range("Shadow_KS_Modules_col").Cells(1).End(xlDown))
'KSModulesRng is now the range of modules in column AD
Range("Shadow_KS_Capacity_Area").ClearContents
With Intersect(Range("shadow_KS_Capacity_Area"), KSModulesRng.EntireRow)
.FormulaR1C1 = "=shadow_k_mins!RC[23]-SUMIF(shadow_k_mins!R35C18:R1544C18,shadow_k_mins!RC30,shadow_k_mins!R35C[23]:R1544C[23])"
Application.Calculation = xlCalculationAutomatic
.Value = .Value
End With
Application.ScreenUpdating = True
MsgBox Timer - StartTime & " secs."
End Sub[/vba]
Even if the running times were 100 times faster than the above offerings by going in-memory, the absolute time saved for each run would be a fraction of a second. Not worth doing.
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules