Application.ScreenUpdating not working

Nelsini

New Member
Joined
May 13, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
Hello!

I found and adapted a code that hides columns in which a certain range contains a "0". The problem is, when I run the code, I keep seeing the worksheets activate, even with ScreenUpdating set to False. (running MacOS)

Code:

VBA Code:
Sub Hide_Columns_With_Zero()
Dim cl, rTest As Range

Application.ScreenUpdating = False

Worksheets("Errors test").Activate
Set rTest = Sheets("Errors test").Range("B7:N7", Range("B7:N7").End(xlToRight))

For Each cl In rTest
    If cl.Value = 0 Then
        cl.EntireColumn.Hidden = True
    Else
        cl.EntireColumn.Hidden = False
    End If
Next cl


Worksheets("Monthly Data").Activate
Set rTest = Sheets("Monthly Data").Range("A7:Q7", Range("A7:Q7").End(xlToRight))

For Each cl In rTest
    If cl.Value = 0 Then
        cl.EntireColumn.Hidden = True
    Else
        cl.EntireColumn.Hidden = False
    End If
Next cl

Application.ScreenUpdating = True
End Sub

I had to add the "Worksheets.Activate" because the code wouldn't run if I didn't have the sheet selected.

Any help is appreciated!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You need to qualify both ranges with the sheet like this
VBA Code:
Set rTest = Sheets("Errors test").Range("B7:N7", Sheets("Errors test").Range("B7:N7").End(xlToRight))
Than you shouldn't need to activate the sheet
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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