VBA is turning off automatic workbook calculations

mst3k4L

Board Regular
Joined
Nov 3, 2011
Messages
55
Whenever I run this VBA code, the automatic workbook calculations are turned off, an d I have no idea why. Any ideas would be appreciated.

Code:
Sub solve_verror()
'
' solve_verror Macro
'
    Dim r As Long
    Dim i As Long
    Dim j As Long
    Dim LastRow
    Dim lastColumn
    Dim newColumns
    
    r = 24
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    lastColumn = Cells(21, Columns.Count).End(xlToLeft).Column
    Range(Cells(r, 1), Cells(LastRow, lastColumn)).ClearContents
    
    'Inserts Required columns inside two V_leak summations
    tstep = Range("tstep")
    newColumns = Range("tinj") / tstep
    For j = 1 To (newColumns - 2)
        Columns("E:E").Insert Shift:=xlToLeft, CopyOrigin:=xlFormatFromLeftOrAbove
    Next
    Range(Cells(r - 1, 4), Cells(r - 1, 4)).AutoFill Destination:=Range(Cells(r - 1, 4), Cells(r - 1, 14)), Type:=xlFillDefault

    Do While Cells(r - 1, 1) < Range("tinj")
        Cells(r, 1) = Cells(r - 1, 1) + tstep
        Cells(19, r - 20) = Cells(r, 1)
        Cells(r, 2) = Cells(r, 1) * Range("q")
        Cells(r, 3) = Cells(r - 1, 3) + 1
        
        'Autofill has to include the original selected range
        Range(Cells(r - 1, 4), Cells(r - 1, 22)).AutoFill Destination:=Range(Cells(r - 1, 4), Cells(r, 22)), Type:=xlFillDefault
        Rows(20).Clear
        'Places variable on length row on top to match L_estimated column
        For i = 23 To LastRow
            Cells(20, i - 20).Formula = "=C" & i
        Next
        
        SolverOk SetCell:=Cells(r, 20), MaxMinVal:=3, ValueOf:="0", ByChange:=Cells(r, 3)
        SolverSolve UserFinish:=True
   
        SolverSolve (True)
        r = r + 1
    Loop
End Sub
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Warship

Well-known Member
Joined
Jul 17, 2007
Messages
1,051
maybe add this to the end?
Code:
Application.Calculation = xlCalculationAutomatic
 

Watch MrExcel Video

Forum statistics

Threads
1,122,190
Messages
5,594,761
Members
413,931
Latest member
acrato

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
Top