Discussion:
stopping a range from calculating
(too old to reply)
Xt
2011-06-28 23:35:13 UTC
Permalink
Hi folks.
I'm in Excel 2007. I have written a macro which accesses values from
a sheet, does things and pastes results back onto that same sheet.
This sheet gets data from another sheet "Data". Column A in Data is
generating random numbers. What I would like to do is be able to stop
and start the calculations in column A in the Data sheet from the
macro at suitable times.
This sounds simple. Can it be done?
Thanks
xt
Vacuum Sealed
2011-06-29 13:46:41 UTC
Permalink
Hi xt

not to sure if you can halt autocalcs on specific rows, columns or
individual cells,.

you can control wheter the woorkbook itself does or does not autocalc.

you could have let's say 2 cmdbtns, one = off, the other = on

Sub Calc_Off()
With Application
.Calculation = xlManual
End With
End Sub

Sub Calc_On()
With Application
.Calculation = xlAutomatic
End With
End Sub

You could also place something in the

Private Sub Workbook_Open()

With Application
.Calculation = xlManual
End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

With Application
.Calculation = xlAutomatic
End With
End Sub

HTH
Mick.
GS
2011-06-29 14:30:56 UTC
Permalink
Post by Xt
Hi folks.
I'm in Excel 2007. I have written a macro which accesses values from
a sheet, does things and pastes results back onto that same sheet.
This sheet gets data from another sheet "Data". Column A in Data is
generating random numbers. What I would like to do is be able to stop
and start the calculations in column A in the Data sheet from the
macro at suitable times.
This sounds simple. Can it be done?
Thanks
xt
Mick's suggestion[s] would be the first approach, but turning calc off
also prevents all other cells from updating. If you need those to calc
as your macro returns values, you can turn calc OFF and just update
$A:$A when needed.

Example:

Range("$A:$A").Calculate

OR, if you need calc turned ON you might be able to use a workaround...

Put the ColA formulas in a hidden column as Text (ie: format the cells
as 'Text').

In your macro, ClearContents of $A:$A prior to running the code that
changes values. Afterwards, update $A:$A with the hidden formulas.

Example:

With Range("$A:$A")
.ClearContents

'//code to return values here

.Formula = Range("HiddenFormulas").Value
End With 'Range("$A:$A")


Alternatively, you could load the data into an array and process the
array, then 'dump' the data back into the worksheet in one shot. Not
sure this scenario will work for you but it will allow you to process
the data without affecting any worksheet data during the process. It
would also be considerably faster than reading/writing to the worksheet
for each piece of data being processed.
--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
GS
2011-06-29 14:32:39 UTC
Permalink
Typo...
Mick's suggestion[s] would be the first approach, but turning calc off also
prevents all other cells from updating. If you don't need those to calc
as your
macro returns values, you can turn calc OFF and just update $A:$A when
needed.
--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
joeu2004
2011-06-30 19:31:59 UTC
Permalink
Post by Xt
I have written a macro which accesses values from
a sheet, does things and pastes results back onto that same
sheet. This sheet gets data from another sheet "Data".
 Column A in Data is generating random numbers.  What I would
like to do is be able to stop and start the calculations in
column A in the Data sheet from the macro at suitable times.
This sounds simple.  Can it be done?
Yes, if I understand you correctly. First, you should bracket your
code with the following:

Dim oldCalc
oldCalc = Application.Calculation
Application.Calculation = xlCaculationManual
... your code...
Application.Calculation = oldCalc

Now, within your code, when you want to generate a new set of random
values in Data!A:A, you can write:

Sheets("data").Range("a:a").Calculate
Xt
2011-07-01 21:31:58 UTC
Permalink
Post by Xt
I have written a macro which accesses values from
a sheet, does things and pastes results back onto that same
sheet.  This sheet gets data from another sheet "Data".
 Column A in Data is generating random numbers.  What I would
like to do is be able to stop and start the calculations in
column A in the Data sheet from the macro at suitable times.
This sounds simple.  Can it be done?
Yes, if I understand you correctly.  First, you should bracket your
Dim oldCalc
oldCalc = Application.Calculation
Application.Calculation = xlCaculationManual
... your code...
Application.Calculation = oldCalc
Now, within your code, when you want to generate a new set of random
Sheets("data").Range("a:a").Calculate
Thanks a lot for all that advice. With your help I've got things
going as I want.

Cheers, xt

Continue reading on narkive:
Loading...