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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,216,038
Messages
6,128,447
Members
449,453
Latest member
jayeshw

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