Application.ScreenUpdating automatically changes to True

pecosvil

Board Regular
Joined
Apr 13, 2010
Messages
52
I have a code that initially sets ScreenUpdating to False, but in the middle of the code it calls another subroutine and for some reason it actually shows me some (not all) actions (ie, when it selects a new sheet I get to see that). I have been following ScreenUpdating Property through Debug.Print Application.ScreenUpdating and it always stays as FALSE.

Here is a simplified version of the code

Code:
Option Explicit


Sub Check_InputData()


Application.ScreenUpdating = False
Application.EnableEvents = False

Worksheets("Instructions").Calculate
Worksheets("Lists").Calculate
Call DP_disbursement
Worksheets("DP").Calculate 

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

The subroutine DP_disbursement is located in a different module (is that relevant?). The code is more or less the following:

Code:
Sub DP_disbursement()

Dim number_disbursements As Integer
Application.EnableEvents = False


Worksheets("DP").Unprotect
Worksheets("DP").Select
ActiveSheet.Calculate
Range("B43:C72").Copy


Range("D43").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("D43").Select
    ActiveSheet.Calculate
Range("A1").Select
Worksheets("DP").Protect


Application.EnableEvents = True 


End Sub

Anyone ideas? Thanks in advance!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try replacing the latter sub with this:

Code:
Sub DP_disbursement()
    Application.EnableEvents = False
    
    With Worksheets("DP")
        .Unprotect
        .Calculate
        With .Range("B43:C72")
            .Range("D43").Resize(.Rows.Count, .Columns.Count).Value = .Value
        End With
        .Calculate
        .Protect
    End With
    Application.EnableEvents = True
End Sub
 
Upvote 0
Try to avoid selecting objects - a good general principle. Not sure, but in your called routine the selecting may be what triggers a screen update. Try this version to see if it helps:
Code:
Sub DP_disbursement()

Dim number_disbursements As Integer
Application.EnableEvents = False


Worksheets("DP").Unprotect
Worksheets("DP").Calculate
Range("B43:C72").Copy


Range("D43").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
'    Range("D43").Select
    ActiveSheet.Calculate
'Range("A1").Select
Worksheets("DP").Protect


Application.EnableEvents = True


End Sub
 
Upvote 0
Thanks to both. Indeed, I changed the code to avoid using .Select and .Activate, and it worked fine. So the problem is solved.
Still, any ideas why the ScreenUpdating = False doesn't work when I select a different sheet? Isn't it suppose to work exactly for that?

Is it because the selection was performed in a different sub? in a different module? and why does the Debug.Print Application.ScreenUpdating didn't catch any change in the ScreenUpdating Property?
 
Upvote 0
Does the debug.print reside in the main sub or the called sub?
 
Upvote 0
in both. I put a debug.print before calling the sub. And then put a debug.print before/after each line (including before after the select line). and then put a debug print after the called sub ends and the code returns to the original sub. in all cases it was FALSE.
 
Upvote 0
in both. I put a debug.print before calling the sub. And then put a debug.print before/after each line (including before after the select line). and then put a debug print after the called sub ends and the code returns to the original sub. in all cases it was FALSE.
What happens if using your original sub with the selects in it you add Application.ScreenUpdating = false at its start?
 
Upvote 0
That was the first thing I tried. I was still experiencing the same problem...



Well that narrows it down to the selecting I guess, and I guess further that it's specifically the selection of a sheet that wasn't the active sheet when you launched the macro. A selected sheet comes to the top even though screen updating is off. So, the debug.prints are correct, reflecting the fact that screen updating is off.
 
Upvote 0

Forum statistics

Threads
1,223,708
Messages
6,174,006
Members
452,542
Latest member
Bricklin

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
Back
Top