View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Memory Overflow issue (clear worksheet that has Worksheet_Change action)

Hi Garry. Thanks for the explanation. This worked beautifully. And
I
now understand what you are saying, and I see this is a replacement
fo
rmy other copy cells code. I've also got a few lines of code that
run
at the beginning and end of my larger modules that turn off screen
updating and calculations, and when I saw the EnableEvents and
ScreenUpdating line, I just thought this needed to go there. I'm
good
to go for this piece of my puzzle. Thank you!!


You're very welcome!

FWIW
Here's how I handle enabling/disabling fast code. It uses a global Type
to manage which procedures turn things off/on so you don't run into
unexpected issues...

'--------------------------------------------------------------------------------------
' **Note: EnableFastCode requires the following declarations be in a
standard module.
'--------------------------------------------------------------------------------------
'Type udtAppModes
' 'Default types
' Events As Boolean: CalcMode As XlCalculation: Display As Boolean:
CallerID As String
' 'Project-specific types
'End Type
'Public AppMode As udtAppModes
'--------------------------------------------------------------------------------------
Sub EnableFastCode(Caller$, Optional SetFast As Boolean = True)
' **Note: Requires 'Type udtAppModes' and 'Public AppMode As
udtAppModes' declarations

'The following will make sure only the Caller has control,
'and allows any Caller to take control when not in use.
If AppMode.CallerID < Caller Then _
If AppMode.CallerID < "" Then Exit Sub

With Application
If SetFast Then
AppMode.Display = .ScreenUpdating: .ScreenUpdating = False
AppMode.CalcMode = .Calculation: .Calculation =
xlCalculationManual
AppMode.Events = .EnableEvents: .EnableEvents = False
AppMode.CallerID = Caller
Else
.ScreenUpdating = AppMode.Display
.Calculation = AppMode.CalcMode
.EnableEvents = AppMode.Events
AppMode.CallerID = ""
End If
End With
End Sub

...and here's how to set your projects up to use it...

Sub DoTask()
Const sSource$ = "DoTask"

EnableFastCode sSource
'do intensive stuff
EnableFastCode sSource, False
End Sub

...where sSource holds the name of the procedure (Sub or Function) that
would use this. If already in use by another procedure, EnableFastCode
will not get toggled.

Note:
The const sSource is also used for error logging and so is
multi-purpose in my projects!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus