Run Time Issue

S

Steph

Hello. I am running some code that clears a range of cells on
multiple sheets, then populates the same sheets with data being pulled
from a database-like worksheet. My question is this: Sometimes when
I run the code, it takes 20 seconds. Majority of the time I run the
code it takes 6 minutes! IS there data in a cache or something that
is forcing things to run so slowly? Usually, when I first open the
file and the sheets are already blank, it runs quickly. If I run it
again when the sheets are already populated, it takes forever! So I
thought it was just the sheer size of the file after being populated
that slowed things. BUT, then I selected every sheet, and hit the
home key. And when I ran the code, it ran in 20 seconds! I am SO
confused!! Anyone have any ideas on how to get the code to
consistently run quickly? The code is below. Thanks so much!!

Sub Run_Forecast()
Clear
Pop_Forecast
End Sub

Sub Clear()

Dim sh As Worksheet

Application.ScreenUpdating = False

clrarray = Array("Forecast", "LMU", "Kit", "SMLC", "WLG", "SMLC Cab",
"Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup")

For Each sh In ActiveWorkbook.Worksheets(clrarray)
' Sheets("SMLC Cab").Range("A1").Select
' sh.Range("A1").Select
sh.Range("A5:EC500").ClearContents
Next sh
Application.ScreenUpdating = True

End Sub

Sub Pop_Forecast()

Dim shtarray As Sheets
Dim frng As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

Set shtarray = Sheets(Array("LMU", "Kit", "SMLC", "WLG", "SMLC Cab",
"Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup"))

shtarray.Select
Sheets("LMU").Activate

'Copy Formula
Range("A2:EC2").Copy

Set frng = Range("A5:EC" & Data.Range("b65536").End(xlUp).Row)
frng.Select
Selection.PasteSpecial Paste:=xlPasteFormulas

'Consolidate2
Forecast.Range("A5").Consolidate Sources:=Array( _
"'LMU'!R5C5:R500C133" _
, "'Kit'!R5C5:R500C133" _
, "'SMLC'!R5C5:R500C133" _
, "'WLG'!R5C5:R500C133" _
, "'SMLC Cab'!R5C5:R500C133" _
, "'Serv Cab'!R5C5:R500C133" _
, "'Ntwk Kit'!R5C5:R500C133" _
, "'TDAX'!R5C5:R500C133" _
, "'EMS'!R5C5:R500C133" _
, "'SCOUT'!R5C5:R500C133" _
, "'Dir Coup'!R5C5:R500C133" _
), Function:=xlSum, TopRow:=False, LeftColumn:=True,
CreateLinks:=False

Forecast.Activate

Application.ScreenUpdating = True

End Sub
 
B

Bob Phillips

Steph,

Try setting the Application calculation property to xlCalculationManual
before the code, and reset to xlCalculationAutomatic after.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Variant Array 1
Consolidate Range 0
Any ideas? 1
Extremely slow run-time 6
Literally - every other time 0
Why won't this work? 3
More efficient way? 6
Fastest way to clear contents 3

Top