Display VBA Code in Excel

This guide treats “display vba code in excel” the way busy spreadsheet users actually want it: answer first, then the reasoning. It is written for Excel but calls out every place Google Sheets differs, and the platform toggle at the top switches all shortcuts between Windows and Mac so nothing here assumes the keyboard you are not on.

Exact answer

In Excel: Press Alt + F11 (Option + F11 on Mac) to open the Visual Basic Editor, then use Insert ▸ Module to create a place to write code.

VBA macro: Open the VBA Editor

Sub HelloFromTheEditor()
    MsgBox "The VBA editor is working — this macro ran from the module you just created.", _
           vbInformation, "VBA Editor"
End Sub

Paste this into the blank Module window and press F5. A dialog means the editor, the module and macro security are all set up correctly, so any later code you paste will run too.

How to run this macro

  1. Press Alt + F11 to open the VBA editor.
  2. Insert > Module.
  3. Paste the code above.
  4. Press F5, or close the editor and run it from Developer > Macros.
  5. Save the file as .xlsm so the macro is kept.
Annotated stepsExcel
1

Press Alt + F11 from any worksheet (Option + F11 on Mac; on some laptops you also need the Fn key).

2

If the Project Explorer pane is missing on the left, press Ctrl + R to bring it back.

3

Expand the tree entry for your workbook, then expand Modules to read code that already exists.

4

To write new code, right-click the workbook name and choose Insert ▸ Module — the code window stays blank until a module is open.

5

Press Alt + F11 again to switch back to the sheet; the editor stays open in the background.

Ctrl+CthenCtrl+Shift+V+Cthen+Ctrl+VPaste values · WindowsMac

What this does

The Visual Basic Editor is a separate application window that ships inside Excel — it is where every macro in a workbook actually lives. Alt + F11 opens it from any sheet, with no setup and no Developer tab required. The editor is split into three panes. On the left, the Project Explorer lists every open workbook and add-in as a tree: sheet objects, ThisWorkbook, and any Modules the file contains. Below it, the Properties window shows the attributes of whatever is selected. The large area on the right is the code window, which stays blank until you open a module — a common reason people think the editor is broken on first launch. Existing macros are inside those Modules, so to read code someone else wrote, expand Modules in the tree and double-click one. Press Ctrl + G to add the Immediate window, where Debug.Print output lands. The same idea underpins a lot of everyday Excel work, so the few minutes spent getting it right here pay back across every sheet you build afterwards. Treat it as a pattern, not a one-off, and it stops being something you look up and starts being something you reach for. For “display vba code in excel”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected cells change, and only then apply the same setup to the full sheet. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That is what makes a workflow that saves repeating the same clicks every week useful in real work: repeatable, auditable, and not dependent on memory or luck.

A worked example

You inherit a workbook and want to see what it does before trusting it. Press Alt + F11. In the Project Explorer on the left, find the entry matching the file name, click the plus beside it, and expand the Modules folder. Double-click Module1 and its code appears on the right. If there is no Modules folder, the automation lives in a sheet object or in ThisWorkbook instead — double-click those to check. To write something of your own rather than read, right-click the workbook name, choose Insert ▸ Module, paste Sub HelloFromTheEditor() into the empty window, and press F5. Alt + F11 toggles back to the spreadsheet, and both windows stay open side by side. Every other macro task starts here, so knowing the editor layout turns a wall of unfamiliar panes into two clicks. It is also the fastest way to audit an unfamiliar workbook before you enable its macros: read the code first, decide second. If there is any chance you will reuse this, drop it into a small template tab right now: a labelled input area on the left and the formula beside it, checked once against the tool above. Next time the same question comes up, the answer is a single paste away instead of a rebuild from memory.

In Google Sheets

If you are in Google Sheets rather than Excel, the good news is that the formula shown here is identical and the workflow barely changes — menus sit across the top instead of in a ribbon, and a few function names differ slightly, but anything you build here moves across with little or no rework. The aim was to get you unstuck fast and leave you a little more capable than a copy-paste would. The answer is at the top, the tool proves it, and the detail above shows why it holds — so the next time a colleague asks, you can answer without reaching for search. Treat “display vba code in excel” as a small building block rather than a chore. Once the inputs sit in their own cells and the formula reads from them, the same setup answers a dozen related questions with a tweak, and Excel keeps every dependent figure current as the data changes. The tool above is there so you can rehearse and verify before committing anything to a real workbook; the steps and worked example are there so the logic sticks. Get it right once and it stops costing you time — it starts saving it, every time the question comes back around.

Common mistakes

  • Expecting the Developer tab to be there first. It is not needed — Alt + F11 works whether or not the tab is visible. If you do want it, turn it on under File ▸ Options ▸ Customize Ribbon by ticking Developer.
  • Typing into the grey background of the editor. That area is not a code surface; nothing accepts input until a Module (or a sheet object) is open in a code window.
  • Writing a macro inside a sheet object such as Sheet1 when a standard module was meant. Code in a sheet object is scoped to that sheet and will not appear in the Developer ▸ Macros list, which makes it look like the macro vanished.
  • Assuming a workbook has no code because Modules is empty. Event handlers live in ThisWorkbook and in the individual sheet objects, so check those before concluding the file is macro-free.

Frequently asked questions

Does Alt + F11 work on a Mac?

Option + F11 opens the editor on Mac, and on keyboards where the function keys default to media controls you need Fn + Option + F11. Tools ▸ Macro ▸ Visual Basic Editor from the menu bar always works as a fallback.

The editor opened but the window is completely blank — is it broken?

No. The code pane is empty until a module is open. Press Ctrl + R for the Project Explorer, then either double-click an existing module or use Insert ▸ Module to create one.

How do I see the VBA code someone else wrote in a workbook?

Alt + F11, expand the workbook in the Project Explorer, then expand Modules and double-click each one. Also check ThisWorkbook and the sheet entries — event code lives there rather than in a module.

Why is the project locked and asking for a password?

The author protected it under Tools ▸ VBAProject Properties ▸ Protection. Without that password the code cannot be viewed, and there is no supported way around it — ask whoever built the file.