Turn off calculating multiple workbooks in a macro

Peter Davison

Active Member
Joined
Jun 4, 2020
Messages
435
Office Version
  1. 365
Platform
  1. Windows
Hi,
I've got a macro that does a "Solver" calculation that updates many cells in 5 different workbooks.
I think the macro would run quicker if the workbooks were not updating all the time. (They are all open)
Is there a way of adding code to the macro so any updating of the 5 workbooks are completed at the end of the macro?
I've attached the Macro for information
VBA Code:
Thanks for your assistance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I did not see anything attached. :)
 
Upvote 0
Private Sub CommandButton1_Click()



Dim i As Long

Set wsstart = Sheets("Start Data1")
Set wsanalyse = Sheets("Analyse1")
Set wsresult = Sheets("Result1")


'Clear cells and copy formula as a value to bring in the attribute 1 data
Worksheets("Start Data1").Range("E17").Select
Worksheets("Start Data1").Range("E17:AW500").Clear
Worksheets("Start Data1").Range("D15").Select
Selection.Copy
Worksheets("Start Data1").Range("E17:AW500").Select
ActiveSheet.Paste
Worksheets("Start Data1").Range("E17:AW500").Value = Worksheets("Start Data1").Range("E17:AW500").Value
Application.CutCopyMode = False


wsanalyse.Activate

'Do Clusters 10 - 2
For i = 10 To 2 Step -1

wsstart.Range("b2:b10").Copy wsanalyse.Range("D2")
wsstart.Range("c1:c" & i).Copy wsanalyse.Range("D1")

SolverReset

SolverOk SetCell:="$DG$5", MaxMinVal:=2, ValueOf:="0", ByChange:=("$D$1:$D$" & i), Engine:=3, EngineDesc:="Evolutionary"

SolverAdd CellRef:=("$D$1:$D$" & i), Relation:=1, FormulaText:="100"
SolverAdd CellRef:=("$D$1:$D$" & i), Relation:=4, FormulaText:="Integer"
SolverAdd CellRef:=("$D$1:$D$" & i), Relation:=3, FormulaText:="1"

SolverOptions MaxTime:=120, Iterations:=0, PopulationSize:=False, RandomSeed:=1, MutationRate:=0.075, _
RequireBounds:=True, MaxIntegerSols:=0

SolverSolve UserFinish:=True

wsresult.Range("EE3:Eq500").Offset(0, 13 * (10 - i)) = wsanalyse.Range("CV3:Dh500").Value
Next i

wsresult.Activate
wsresult.Range("IM1").Select

'ActiveWorkbook.Save

MsgBox "Complete"



End Sub
 
Upvote 0
Do you think it is as simple as - in the macro at the beginning activating each workbook in turn and switching off automatic updating and then at the end of the macro switching automatic updating back on?
If you think it might be what would be the code to do that?

Thanks
 
Upvote 0
Do you think it is as simple as - in the macro at the beginning activating each workbook in turn and switching off automatic updating and then at the end of the macro switching automatic updating back on?
If you think it might be what would be the code to do that?

Thanks
That would be
VBA Code:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

<your program>

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

Let me know if it works but I think switching between workbooks will negate it.
 
Upvote 0
Solution
Yes you are correct it does not work switching off workbook updating.
Not to worry, I will have to think again.
Thanks for your help.
 
Upvote 0
Yes you are correct it does not work switching off workbook updating.
Not to worry, I will have to think again.
Thanks for your help.
Maybe it is possible to use xlMinimized. Perhap this will speed up. Open other workbooks minimized. Try something like this:
Rich (BB code):
Dim wb as Workbook
Dim wbName as Window

Set wb = ActiveWorkbook
Set wbName = Windows(<workbook name>)
or
Set wbName = Windows(wb.Name)

wb.ScreenUpdating=False
wbName.WindowState = xlMinimized

.... your code .....

wb.ScreenUpdating=True

I think no need to use wb.ScreenUpdating=False since it did not work before.

The wb.ScreenUpdating=False will work on current workbook that runs macro. Once switching control to another workbook, the setting get nullified, thus no longer take effect even when the macro return control to current workbook.
 
Upvote 0
Thank you for this. I am away on work over the next couple od days but when I return I will test it.
Thank you for all you help
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top