VBA Code ignores some sheets

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
149
Hey, guys,
I'm using a macro do to some basic tasks. However, it keeps ignoring some of the worksheets.
Any idea why?

Code:
Sub Macro1()
Dim w as worksheet
Application.ScreenUpdating = False


For Each w In Worksheets


    ActiveWindow.DisplayGridlines = False
    ActiveWindow.Zoom = 85
    Range("A1").Select


Next


Application.ScreenUpdating = True


End Sub

Thanks
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You need to select each sheet for that to work:

Rich (BB code):
Sub Macro1()

Application.ScreenUpdating = False


For Each Sheet In Worksheets

Sheet.Select
    ActiveWindow.DisplayGridlines = False
    ActiveWindow.Zoom = 85
    Range("A1").Select


Next


Application.ScreenUpdating = True


End Sub
 
Upvote 0
You need to select each sheet for that to work:

Rich (BB code):
Sub Macro1()

Application.ScreenUpdating = False


For Each Sheet In Worksheets

Sheet.Select
    ActiveWindow.DisplayGridlines = False
    ActiveWindow.Zoom = 85
    Range("A1").Select


Next


Application.ScreenUpdating = True


End Sub

Thanks, Rory. It worked perfectly!

Would it be possible to do it without using Sheet.Select? I figured "ActiveWindow" was the problem and was trying to replace it with "ActiveSheet" but it didn't work
 
Last edited:
Upvote 0
No, you can't set the Zoom or select a cell on a sheet without it being active.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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