ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA loop slow if another workbook open (https://www.excelbanter.com/excel-discussion-misc-queries/204322-vba-loop-slow-if-another-workbook-open.html)

George[_8_]

VBA loop slow if another workbook open
 
I have a longish do-while loop in a VBA fnc. (code, below) If only
this workbook is open, it completes in < 1 sec. If any other workbook
is open, execution time increases to many seconds.

My guess is that the 'application.calculate' is giving up the baton to
any other workbook, and the task switching is causing the slowdown. Is
this plausible?

Bottom line: ss there a way to speed this up? Any ideas would be
appreciated.

Thanks,
George

--------------------------------
Loop code:

Do
N = 200
Do
N = N - 1

Range("wt_use").Value = Range("wt_new").Value

Range("control").Value = _
Range("control").Value + Range("adj").Value

Application.Calculate
Loop While ((Abs(Range("min_err").Value) 0.01) _
And (N 0))
M = M + 1
Loop While ((Range("max_chg").Value 0.01))



Stefi

VBA loop slow if another workbook open
 
Try this:

Application.Calculation = xlManual
Do
....
ActiveSheet.Calculate
Loop
Application.Calculation = xlAutomatic

Regards,
Stefi

€˛George€¯ ezt Ć*rta:

I have a longish do-while loop in a VBA fnc. (code, below) If only
this workbook is open, it completes in < 1 sec. If any other workbook
is open, execution time increases to many seconds.

My guess is that the 'application.calculate' is giving up the baton to
any other workbook, and the task switching is causing the slowdown. Is
this plausible?

Bottom line: ss there a way to speed this up? Any ideas would be
appreciated.

Thanks,
George

--------------------------------
Loop code:

Do
N = 200
Do
N = N - 1

Range("wt_use").Value = Range("wt_new").Value

Range("control").Value = _
Range("control").Value + Range("adj").Value

Application.Calculate
Loop While ((Abs(Range("min_err").Value) 0.01) _
And (N 0))
M = M + 1
Loop While ((Range("max_chg").Value 0.01))




George[_8_]

VBA loop slow if another workbook open
 
Much better. Thanks.

G


On Mon, 29 Sep 2008 05:09:01 -0700, Stefi
wrote:

Try this:

Application.Calculation = xlManual
Do
...
ActiveSheet.Calculate
Loop
Application.Calculation = xlAutomatic

Regards,
Stefi

„George” ezt ķrta:

I have a longish do-while loop in a VBA fnc. (code, below) If only
this workbook is open, it completes in < 1 sec. If any other workbook
is open, execution time increases to many seconds. ...




Stefi

VBA loop slow if another workbook open
 
You are welcome! Thanks for the feedback!
Stefi

€˛George€¯ ezt Ć*rta:

Much better. Thanks.

G


On Mon, 29 Sep 2008 05:09:01 -0700, Stefi
wrote:

Try this:

Application.Calculation = xlManual
Do
...
ActiveSheet.Calculate
Loop
Application.Calculation = xlAutomatic

Regards,
Stefi

€˛George€¯ ezt Ć*rta:

I have a longish do-while loop in a VBA fnc. (code, below) If only
this workbook is open, it completes in < 1 sec. If any other workbook
is open, execution time increases to many seconds. ...






All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com