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
|