Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default VBA Application.xlCalculationManual

Hello all

I know that setting calculation mode to xlManual will speed Excel VBA up.
But are there any situations where it can cause incorrect results etc.

Say I have a range of cells that I need to loop through twice (or more than
once anyway). Once to test cell contents & then possibly change some cell
values. Now I need to loop through the same range again to do something else
after this first test.

Can I have calculation set to xlManual for the whole routine or will this
prevent the changes from the "first" loop being used in the second loop?

Basically, I'm doing a "find & replace" first time through the loop, then
looping through again to do something else based on the cell contents AFTER
the find & replace.

Does this create a problem or not? Hope I have explained myself correctly.

Thanks
Tony McGee




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA Application.xlCalculationManual

Here is an example.

Sub AABB()
Range("A1").Formula = "=B1 + 5"
Range("B1").Value = 10
Application.Calculation = xlManual
s = Range("A1").Value
Range("B1").Value = 20
s = s & "," & Range("A1").Value
Debug.Print s
Application.Calculation = xlAutomatic
End Sub

It returns

15,15

when I comment out the Calculation = xlManual

Sub AABB()
Range("A1").Formula = "=B1 + 5"
Range("B1").Value = 10
'Application.Calculation = xlManual
s = Range("A1").Value
Range("B1").Value = 20
s = s & "," & Range("A1").Value
Debug.Print s
Application.Calculation = xlAutomatic
End Sub

it returns
15,25

So if you need to get the value of a cell that is the result of calculation,
then it could have an adverse affect.

--
Regards,
Tom Ogilvy


"Tony McGee" wrote in message
...
Hello all

I know that setting calculation mode to xlManual will speed Excel VBA up.
But are there any situations where it can cause incorrect results etc.

Say I have a range of cells that I need to loop through twice (or more
than
once anyway). Once to test cell contents & then possibly change some cell
values. Now I need to loop through the same range again to do something
else
after this first test.

Can I have calculation set to xlManual for the whole routine or will this
prevent the changes from the "first" loop being used in the second loop?

Basically, I'm doing a "find & replace" first time through the loop, then
looping through again to do something else based on the cell contents
AFTER
the find & replace.

Does this create a problem or not? Hope I have explained myself correctly.

Thanks
Tony McGee






  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default VBA Application.xlCalculationManual

As long as none of the cells in your range contain formulas (or are the
result of calculations) that depend on the cell values you changed - you
should be okay. If you are dealing with hardcoded data, VBA will use the new
values.

Tom showed VBA did not recognize the new value of cell A1 (which was a
calculation based on cell B1). But VBA should recognize the value of B1 was
changed. To slightly modify his example:

Sub AABB()
Range("A1").Formula = "=B1 + 5"
Range("B1").Value = 10
Application.Calculation = xlManual
s = Range("B1").Value
Range("B1").Value = 20
s = s & "," & Range("B1").Value
Debug.Print s
Application.Calculation = xlAutomatic
End Sub

will return 10, 20



"Tony McGee" wrote:

Hello all

I know that setting calculation mode to xlManual will speed Excel VBA up.
But are there any situations where it can cause incorrect results etc.

Say I have a range of cells that I need to loop through twice (or more than
once anyway). Once to test cell contents & then possibly change some cell
values. Now I need to loop through the same range again to do something else
after this first test.

Can I have calculation set to xlManual for the whole routine or will this
prevent the changes from the "first" loop being used in the second loop?

Basically, I'm doing a "find & replace" first time through the loop, then
looping through again to do something else based on the cell contents AFTER
the find & replace.

Does this create a problem or not? Hope I have explained myself correctly.

Thanks
Tony McGee





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
Application.Calculation = xlCalculationManual fails AM Excel Programming 1 June 9th 06 12:23 AM
Application.Calculation = xlCalculationManual mystery David Excel Programming 2 July 13th 05 09:56 AM
How to set in XLA calculation on xlCalculationManual Billy[_5_] Excel Programming 6 September 20th 04 07:57 AM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
Application.Calculation=xlCalculationManual causing run time error? Dave Peterson[_3_] Excel Programming 3 October 18th 03 12:51 AM


All times are GMT +1. The time now is 10:17 PM.

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

About Us

"It's about Microsoft Excel"