P
Peter T
Hi All,
Come across an issue whereby writing to cells in a long loop with
calculation set to Manual can cause the following:
After running for 5-10 seconds
- cells no longer visually update
- cannot abort the macro with Esc or Ctrl-break
- Excel's caption might say "Not responding"
- and similar in the task manager (Ctrl-alt-del)
- doing End task in the task manager crashes Excel
Even if the above occurs the loop seems to continue normally in the
background until it comes to a natural end.
I've tested this in 4 systems, 2 run fine but 2 exhibit the above symptoms.
It has been suggested that this may be due to the system not updating
quickly enough, I'm not sure about that as one of the systems that works
fine is very old.
If anyone would care to test "TestManCalc() below I'd be interested in
results, something like this
works normally or displays symptoms,
Excel version & OS
if possible brief details of hardware
Before running ensure you have no unsaved data in Excel, particularly if
you're up for trying End task if you get the above, ie cells stop visually
updating.
Thanks,
Peter T
pmbthornton gmail com
Option Explicit
Const nLimit As Long = 50000 ' adjust to change when the loop terminates
' suggest assign the 4 Test routines to Forms buttons on the sheet
' or run via Alt-F8
Sub TestManCalc()
Static bWarned As Boolean
If Not bWarned Then
If MsgBox("If you are not ready for the possibility of" & vbCr & _
"crashing Excel press Cancel", _
vbOKCancel Or vbDefaultButton2, _
"one off warning") <> vbOK Then Exit Sub
bWarned = True
End If
LongLoop sInfo:="ManualCalc with Re-calcs"
End Sub
Sub TestInterCalc() '
LongLoop bReCalc:=True, sInfo:="ManualCalc with Re-calcs"
End Sub
Sub TestInterDoEvnts()
LongLoop bDoEvnts:=True, sInfo:="ManualCalc with DoEvents"
End Sub
Sub TestAutoCalc() '
LongLoop bMacCalc:=False, sInfo:="AutomaticCalc"
End Sub
Sub LongLoop(Optional bMacCalc As Boolean = True, _
Optional bReCalc As Boolean = False, _
Optional bDoEvnts As Boolean = False, _
Optional sInfo As String)
Dim bFlag As Boolean
Dim i As Long, j As Long
Range("B7") = sInfo
Range("B33") = Array("number", "number", "formula")
Range("B4:C4").Value = 0
Range("D4").Formula = "=1 * B4 * C4"
If bMacCalc Then
Application.Calculation = xlCalculationManual
End If
On Error GoTo errH
Application.EnableCancelKey = xlErrorHandler ' allow abort with Esc
bFlag = True
While bFlag = True
j = j + 1
'Range("C4") = j
Range("C4") = Range("C4") + 1
If bReCalc Then
Application.Calculate
ElseIf bDoEvnts Then
DoEvents
End If
Range("B4") = 0
For i = 1 To 2000 '
'Range("B4") = i
Range("B4") = Range("B4") + 1
Next
bFlag = (i - 1) * j < nLimit
Wend
done:
Application.EnableCancelKey = xlInterrupt
Application.Calculation = xlCalculationAutomatic
Exit Sub
errH:
Resume done
End Sub
Come across an issue whereby writing to cells in a long loop with
calculation set to Manual can cause the following:
After running for 5-10 seconds
- cells no longer visually update
- cannot abort the macro with Esc or Ctrl-break
- Excel's caption might say "Not responding"
- and similar in the task manager (Ctrl-alt-del)
- doing End task in the task manager crashes Excel
Even if the above occurs the loop seems to continue normally in the
background until it comes to a natural end.
I've tested this in 4 systems, 2 run fine but 2 exhibit the above symptoms.
It has been suggested that this may be due to the system not updating
quickly enough, I'm not sure about that as one of the systems that works
fine is very old.
If anyone would care to test "TestManCalc() below I'd be interested in
results, something like this
works normally or displays symptoms,
Excel version & OS
if possible brief details of hardware
Before running ensure you have no unsaved data in Excel, particularly if
you're up for trying End task if you get the above, ie cells stop visually
updating.
Thanks,
Peter T
pmbthornton gmail com
Option Explicit
Const nLimit As Long = 50000 ' adjust to change when the loop terminates
' suggest assign the 4 Test routines to Forms buttons on the sheet
' or run via Alt-F8
Sub TestManCalc()
Static bWarned As Boolean
If Not bWarned Then
If MsgBox("If you are not ready for the possibility of" & vbCr & _
"crashing Excel press Cancel", _
vbOKCancel Or vbDefaultButton2, _
"one off warning") <> vbOK Then Exit Sub
bWarned = True
End If
LongLoop sInfo:="ManualCalc with Re-calcs"
End Sub
Sub TestInterCalc() '
LongLoop bReCalc:=True, sInfo:="ManualCalc with Re-calcs"
End Sub
Sub TestInterDoEvnts()
LongLoop bDoEvnts:=True, sInfo:="ManualCalc with DoEvents"
End Sub
Sub TestAutoCalc() '
LongLoop bMacCalc:=False, sInfo:="AutomaticCalc"
End Sub
Sub LongLoop(Optional bMacCalc As Boolean = True, _
Optional bReCalc As Boolean = False, _
Optional bDoEvnts As Boolean = False, _
Optional sInfo As String)
Dim bFlag As Boolean
Dim i As Long, j As Long
Range("B7") = sInfo
Range("B33") = Array("number", "number", "formula")
Range("B4:C4").Value = 0
Range("D4").Formula = "=1 * B4 * C4"
If bMacCalc Then
Application.Calculation = xlCalculationManual
End If
On Error GoTo errH
Application.EnableCancelKey = xlErrorHandler ' allow abort with Esc
bFlag = True
While bFlag = True
j = j + 1
'Range("C4") = j
Range("C4") = Range("C4") + 1
If bReCalc Then
Application.Calculate
ElseIf bDoEvnts Then
DoEvents
End If
Range("B4") = 0
For i = 1 To 2000 '
'Range("B4") = i
Range("B4") = Range("B4") + 1
Next
bFlag = (i - 1) * j < nLimit
Wend
done:
Application.EnableCancelKey = xlInterrupt
Application.Calculation = xlCalculationAutomatic
Exit Sub
errH:
Resume done
End Sub