mitikthewalrus
New Member
- Joined
- Nov 11, 2015
- Messages
- 1
I have a short VBA macro that calls a sequence of 6 near-identical subroutines. I've provided one of them below (Year0) as a sample; the others just reference different rows on the same worksheet. If I step through AllYears it works fine to completion, but when I run it, it seems to skip the subs Year1-Year5 and says the calculation is complete without performing the actions. No error messages are given (i.e., the macro doesn't exit early), and the "t" is reported as 0. If I immediately run the macro again, it succeeds with all calculations in 0-1 sec. It consistently runs on the second click, but never the first.
I have already confirmed that "Enable Background Refresh" is unchecked. I tried inserting time delays after each sub, but that didn't seem to help, either. Calculation is automatic at the outset. Any ideas?
Excel 2013
Windows 8
64-bit
I have already confirmed that "Enable Background Refresh" is unchecked. I tried inserting time delays after each sub, but that didn't seem to help, either. Calculation is automatic at the outset. Any ideas?
Excel 2013
Windows 8
64-bit
Code:
Sub AllYears()
'
' Runs base year and all five projection years in sequence
'
Application.Calculation = xlCalculationManual
Dim t As Date
t = Now()
Application.ScreenUpdating = False
Sheets("USCN").Select
Year0
Year1
Year2
Year3
Year4
Year5
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Sheets("Output - Live").Select
MsgBox "Calculation Complete ( " & Format(Now() - t, "s") & "s )"
End Sub
Sub Year0()
Dim limit As Integer
limit = 1000
Dim count As Integer
count = 1
Range("DT120").Value = Range("AF97").Value
Range("A105:DT124").Calculate
Do While (Range("DI122") > 0.00001 And count < limit)
Range("DI107:DR118").Value = Range("D107:M118").Value
Range("DT120").Value = Range("AC122").Value
Range("A105:DT124").Calculate
count = count + 1
Loop
If count >= limit Then
MsgBox ("No solution found for " & ActiveSheet.Name & " -- exiting macro.")
End
End If
End Sub
Last edited: