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