Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default how to reduce execution time of my code?

Experts,

I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I can reduce this
execution time? Here is the code...

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default how to reduce execution time of my code?

This might be quicker

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
.Cells(row_price, j).Value = _
.Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
.Cells(row_price, j + 1).Value = _
.Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



wrote in message
oups.com...
Experts,

I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I can reduce this
execution time? Here is the code...

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default how to reduce execution time of my code?

Is there a lot of calculation going on with these results? The code you
posted should be near instant, but if calculations go off of this new data it
will take a while, you can try turning calculation of before running and
turning it back on at the end of the code, that should fix.
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


" wrote:

Experts,

I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I can reduce this
execution time? Here is the code...

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default how to reduce execution time of my code?

I notice that you use "With wbSource.Worksheets("Flowdate")" yet you still
define your ranges using Worksheets("Flowdate"). You could remove those
references to clean the code up a little.

After looking at your code, I would guess that the formulas on your
worksheet are causing this macro to run a long time. Since you could be
changing values up to 2184 times given the looping in your code,
recalculation can really slow you down.

Try wrapping your code with this:

Application.Calculation = xlManual
' your code here...
Application.Calculation = xlAutomatic

This will cause your macro to make its changes and NOT recalculate until it
is done. Also, consider reviewing your functions to make sure they are
optimized.

HTH,
Pflugs


" wrote:

Experts,

I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I can reduce this
execution time? Here is the code...

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default how to reduce execution time of my code?

That looks simple enough. Perhaps turning off calculation if you have a lot
of formulas

lcalc = Application.Calculation
Application.Calculation = xlManual
With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
Next
MsgBox "Calculation done"
Application.Calculation = lcalc
End With

This assumes you don't need to recalculate the sheet on each
iteration/change made by your code.

--
Regards,
Tom Ogilvy
" wrote:

Experts,

I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I can reduce this
execution time? Here is the code...

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default how to reduce execution time of my code?

One other thought/possibility:

With wbSource.Worksheets("Flowdate")
.DisplayPageBreaks = False

.. . .

--
Regards,
Tom Ogilvy


" wrote:

Experts,

I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I can reduce this
execution time? Here is the code...

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default how to reduce execution time of my code?

Bob,

Your 4 lines reduced my code's execution time to 15 seconds... Its
amazinng!!! I looked into "Help" to understand the usage of these
commands. The excel files I am handelling are of huge sizes and
frequent changes in the screen was increasing the execution time.
Both screenupdating and calculcation worked great for me. Probably I
need to add these in all my relevant macros. :)

Thanks buddy,
Cheers,
Har****

On Aug 9, 8:50 am, "Bob Phillips" wrote:
This might be quicker

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315

For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
.Cells(row_price, j).Value = _
.Cells(row_price, j).Offset(0, 2).Value
End If

offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
.Cells(row_price, j + 1).Value = _
.Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message

oups.com...



Experts,


I am running my macro and its taking almost 5 minutes during execution
on my computer (2GB RAM). Is there any way by which I canreducethis
execution time? Here is the code...


With wbSource.Worksheets("Flowdate")
For j = 24 To 36 Step 4
row_price = 2315


For i = 0 To 364
peak_price = .Cells(row_price, j).Value
If peak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j).Value =
Worksheets("Flowdate").Cells(row_price, j).Offset(0, 2).Value
End If


offpeak_price = .Cells(row_price, j + 1).Value
If offpeak_price = "" Then
Worksheets("Flowdate").Cells(row_price, j + 1).Value =
Worksheets("Flowdate").Cells(row_price, j + 1).Offset(0, 2).Value
End If
row_price = row_price + 1
Next
MsgBox "Calculation done"
Next
End With- Hide quoted text -


- Show quoted text -



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I reduce repetative code leerem Excel Discussion (Misc queries) 4 August 3rd 08 12:20 PM
Any way to reduce/combine in this code? ADK Excel Programming 2 July 11th 07 03:47 PM
Reduce code Excel 2003 - SPB Excel Discussion (Misc queries) 2 May 10th 07 10:43 PM
VBA Code execution delay Raas Excel Programming 1 November 22nd 05 04:00 PM
Code execution has been interrupted Red[_4_] Excel Programming 3 October 6th 05 06:26 AM


All times are GMT +1. The time now is 11:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"