Automatic zoom when new sheet opened

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hey!

Trying to run a script in ThisWorkbook Object that auto zooms to the range selection when a new sheet is selected. I often use two screens and want any sheet I use to automatically zoom into the selection when I switch to it regardless of what screen size i'm using.

This is what I have so far. It currently just resizes the active sheet after I run the macro.

VBA Code:
Sub Worksheet_Zoom()
Dim ws As Worksheet

For Each ws In ThisWorkbook.workSheets
    Range("B1:AD26").Select
    ActiveWindow.Zoom = True
    Range("A1").Select
    
    Next ws
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If you need to zoom on every sheet this could be a solution. Whenever you move to a different sheet the zoom will be activated and deactivated in the previous sheet. These macros must be pasted in the ThisWorkBook module.
VBA Code:
Option Explicit
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Application.ScreenUpdating = False
    Sh.Range("B1:AD80").Select
    ActiveWindow.Zoom = True
    Range("A1").Select
    Application.ScreenUpdating = True
End Sub
Private Sub Workbook_SheetDeActivate(ByVal Sh As Object)
    Application.ScreenUpdating = False
    ActiveWindow.Zoom = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
If you need to zoom on every sheet this could be a solution. Whenever you move to a different sheet the zoom will be activated and deactivated in the previous sheet. These macros must be pasted in the ThisWorkBook module.
VBA Code:
Option Explicit
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Application.ScreenUpdating = False
    Sh.Range("B1:AD80").Select
    ActiveWindow.Zoom = True
    Range("A1").Select
    Application.ScreenUpdating = True
End Sub
Private Sub Workbook_SheetDeActivate(ByVal Sh As Object)
    Application.ScreenUpdating = False
    ActiveWindow.Zoom = False
    Application.ScreenUpdating = True
End Sub
Thankyou! Worked great. Initially when I was returning to a screen that had been zoomed in the display and the cell I clicked mismatched, but I opened the workbook again it seemed to be working fine.
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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