Sometimes, if you want to zoom in and out in a worksheet, you need to have a finger on CTRL and the other on the mouse, you can scroll the wheel on the mouse while pressing CTRL. Is there a simple way to zoom in and out? here is a simple macro that will auto-zoom on double-click.
Zoom In and Out in Worksheet on Double-Click
'------------------ Sheet ------------------
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Check current Zoom state
'Zoom to 100% if to at 100
'Zoom 200% if currently at 100
If ActiveWindow.Zoom <> 100 Then
ActiveWindow.Zoom = 100
Else
ActiveWindow.Zoom = 200
End If
'Note that the side effect of double-clicking a cell is that it goes into edit mode.
'You can exit edit mode by pressing Esc on your keyboard.
'If you find it annoying to repeatedly press Esc when triggering this macro, you can uncomment the next line.
'Application.SendKeys ("{ESC}")
End Sub
How This Macro Works
With this macro in place, you can double-click on a cell in the worksheet to zoom in 200 percent. Double-click again and Excel zooms back to 100 percent. Obviously, you can change the values and complexity in the code to fit your needs.
How to Use This Macro
Most VBA code should be placed in Standard Modules unless specified.
If you see a comment '------------------ Modules------------------
in the code header that means put the code in a Standard Module. For more information, learn this course: Where should I put the Excel VBA code?
The following steps teach you how to put VBA code into a Standard Module:
- Activate the Visual Basic Editor by pressing ALT + F11.
- Right-click the project/workbook name in the Project Window.
- Choose Insert -> Module.
- Type or paste the code in the newly created module. You will probably need to change the sheet name, the range address, and the save location.
- Click Run button on the Visual Basic Editor toolbar.
- For more information, learn this course: Programming with Excel VBA