Skip to main content

Excel Macro: 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

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

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:

  1. Activate the Visual Basic Editor by pressing ALT + F11.
  2. Right-click the project/workbook name in the Project Window.
  3. Choose Insert -> Module.
  4. 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.
  5. Click Run button on the Visual Basic Editor toolbar.
  6. For more information, learn this course: Programming with Excel VBA

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>