To select every cell in the active worksheet with Excel VBA, use Cells.Select — that single line selects the entire sheet, equivalent to clicking the square at the top-left corner where the row and column headers meet. If you want to select only the block of data currently in use, use ActiveSheet.UsedRange.Select instead. Both lines work in any macro-enabled workbook (.xlsm) and require no add-ins. The rest of this guide covers where to put the code, the difference between the two methods, and the errors people hit most often.
What You'll Need
- Excel for Windows or Mac (any recent version) with a workbook saved as .xlsm — macros cannot be stored in a standard .xlsx file.
- The Developer tab visible on the ribbon. If it is not there, go to File > Options > Customize Ribbon and tick Developer in the right-hand list (on Mac: Excel > Preferences > Ribbon & Toolbar).
- Macro security set to allow macros, or the workbook stored in a Trusted Location. Otherwise Excel blocks the code silently.
- Basic familiarity with the VBA editor (VBE). You do not need to know how to program — you only need to paste one or two lines.
Step-by-Step
- Save the workbook as macro-enabled. Go to File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). If you skip this, any code you write is discarded when you close the file.
- Open the VBA editor. Press
Alt + F11on Windows. On Mac, pressOption + F11, or use Tools > Macro > Visual Basic Editor from the menu bar. Labels in the VBE can differ slightly between Excel versions and platforms. - Insert a standard module. In the VBE, go to Insert > Module. A blank code window appears on the right. Do not paste code into the ThisWorkbook or a sheet module unless you specifically want it to run on an event — a standard module is the correct place for a manual macro.
- Paste the selection code. In the blank module, type or paste:
This selects every cell on the active sheet only, not every sheet in the workbook.Sub SelectAllCells() Cells.Select End Sub - Run the macro. Press
F5while the cursor is inside the subroutine, or go back to Excel and use Developer > Macros, pick SelectAllCells, and click Run. The whole sheet should now be highlighted with the selection border around the outside. - Select only the used range instead (optional). If you want just the cells containing data or formatting, replace the middle line with:
This is usually the better choice before copying, formatting or exporting, because it avoids dragging in millions of empty cells.ActiveSheet.UsedRange.Select - Select all cells across every sheet (optional). To loop through the whole workbook, use:
Note that only the last sheet activated will visibly show the selection; the others are selected in turn as the loop runs.Sub SelectAllSheets() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets ws.Activate ws.Cells.Select Next ws End Sub - Save and test. Press
Ctrl + Sin the VBE, close the editor, and run the macro once more from the Developer tab to confirm it behaves as expected.
Common Mistakes
- Using
Selection.SelectorActiveCell.Select. Neither selects the whole sheet — they select what is already selected, or just the active cell. UseCells.Select. - Pasting into a sheet module by accident. Code in a worksheet module only runs on events (like a cell change), not when you press F5 from the Macros dialog. If nothing happens, check the Project Explorer: the code should sit under Modules, not under Microsoft Excel Objects.
- Forgetting to save as .xlsm. The macro runs fine in the session but disappears after closing, because .xlsx cannot store VBA.
- Assuming
Cells.Selectselects every sheet. It only touches the active sheet. Use the loop above if you need all sheets. - Selecting all cells before a copy or format operation. This can be extremely slow on large sheets and can paste formatting into millions of empty cells.
UsedRangeis almost always the right target. - Running the macro while a chart sheet or dialog is active.
Cellsrefers to a worksheet, so the macro errors if the active sheet is a chart. Activate a normal worksheet first.
Tips
- You rarely need to select cells to act on them in VBA.
Cells.Font.Bold = TrueorCells.Interior.Color = vbYellowworks without selecting anything, and it is faster and avoids flicker. - Add
Application.ScreenUpdating = Falseat the start and set it back toTrueat the end if your macro does a lot of work — this stops the screen redrawing on every step. - Use
ActiveSheet.Cells.Selectrather than bareCells.Selectif you want the code to be explicit about which sheet it acts on. Both work, but the explicit form is easier to read later. - To select all cells on a specific named sheet regardless of which is active, use
Worksheets("Sheet1").Cells.Select. The sheet does not need to be active for this to work. - Bind the macro to a keyboard shortcut via Developer > Macros > Options if you run it often.
Troubleshooting
The macro does nothing when you run it. Check that macros are enabled (File > Options > Trust Center > Trust Center Settings > Macro Settings) and that the code is in a standard module. Also confirm you are on a worksheet, not a chart sheet.
You get a "Run-time error 1004" or "Select method of Range class failed". This usually means the sheet is protected. Unprotect it via Review > Unprotect Sheet, or add ActiveSheet.Unprotect (with the password if one is set) before the selection line and re-protect afterwards. It can also happen if the workbook is in a state where selection is not allowed, such as while a modal dialog is open.
The macro is very slow. Selecting all cells on a sheet with a large used range forces Excel to highlight millions of cells. Switch to UsedRange.Select, or better, act on the range directly without selecting it.
The file opens with a security warning every time. That is normal for macro-enabled workbooks. Either click Enable Content each time, or move the file to a folder you have added as a Trusted Location in Trust Center settings.
You cannot find the Developer tab. Right-click any ribbon tab and choose Customize the Ribbon, then tick Developer in the right-hand panel. On Mac, enable it under Excel > Preferences > Ribbon & Toolbar.
Frequently Asked Questions
What is the difference between Cells.Select and UsedRange.Select?
Cells.Select selects every cell on the sheet, including empty ones — over 16,000 columns and over a million rows. UsedRange.Select selects only the rectangle from the first used cell to the last used cell, which is what you usually want.
Does Cells.Select select all sheets in the workbook?
No. It selects all cells on the active sheet only. To cover every sheet, loop through the Worksheets collection as shown in step 7.
Can I select all cells without using VBA?
Yes — click the small square at the intersection of the row and column headers, or press Ctrl + A once (twice if the cursor is inside a data block). The VBA equivalent is just Cells.Select.
Why does my macro fail on a protected sheet?
Excel blocks selection changes on protected sheets. Unprotect the sheet before selecting, then re-protect it at the end of the macro if you need the protection kept.
Will selecting all cells and copying cause problems?
It can. Copying an entire sheet pastes formatting into millions of empty cells, bloats the file and may exceed the clipboard limits. Copy UsedRange instead.
Do I need to activate a sheet before selecting its cells?
No. Worksheets("Sheet1").Cells.Select works without activating the sheet, though the selection will not be visible until you switch to that sheet.