Zoom In and Out in Worksheet on Double-Click

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 VBA Code

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
    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

To use this macro, you can copy and paste it into the Worksheet_BeforeDoubleClick event code window:

  1. Activate the Visual Basic Editor by pressing ALT+F11.
  2. In the Project window, find your project/workbook name and click the plus sign next to it in order to see all the sheets.
  3. Click on the sheet from which you want to trigger the code.
  4. Select the BeforeDoubleClick event from the Event drop-down list:
    Worksheet_BeforeDoubleClick event
  5. Type or paste the code in the newly created module.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>