To select all cells in Excel VBA, use Cells.Select for the whole sheet, ActiveSheet.UsedRange.Select for just the populated area, or Range("A1").CurrentRegion.Select for a contiguous data block. If you need every cell across every sheet, loop the worksheets or use ActiveWorkbook.ActiveSheet.Cells.Select to be explicit about scope. The single most important detail is that Select fails at runtime when the target sheet is not the active one, so activate or select the sheet first, or better, skip selecting altogether and act on the range directly.

What You'll Need

  • Microsoft Excel on Windows or Mac with VBA enabled (the Developer tab visible, or access to the Visual Basic Editor via Alt+F11 on Windows, or Option+F11 on Mac).
  • A workbook saved as .xlsm or .xlsb if you want the macro to persist after closing, since a standard .xlsx file discards VBA code.
  • A basic understanding that code runs against the sheet that is currently active unless you name a sheet explicitly.
  • Optional: a sample worksheet with a few filled cells so you can see the difference between the used range and the whole sheet.

Step-by-Step

  1. Open the Visual Basic Editor. In Excel, press Alt+F11 (Windows) or Option+F11 (Mac), or go to Developer > Visual Basic. Menu labels can differ slightly by version, device and region, so if you do not see the Developer tab, enable it from File > Options > Customize Ribbon (Windows) or Excel > Preferences > Ribbon & Toolbar on Mac.
  2. Insert a module. In the editor, choose Insert > Module. This gives you a blank code window where the macro will live. Avoid pasting into the ThisWorkbook or sheet modules unless you specifically want event-driven code.
  3. Write the simplest select-all statement. Type the following:
    Sub SelectAllCells()
        Cells.Select
    End Sub
    Cells refers to every cell on the active worksheet, and .Select highlights them all exactly as Ctrl+A does on an unused area of the grid.
  4. Run the macro. Place the cursor inside the subroutine and press F5, or close the editor and use Developer > Macros, pick SelectAllCells and click Run. The entire sheet highlights with the marching-ants border.
  5. Select only the used area instead. Select-everything on a full sheet can be slow and memory heavy, and the highlighted block extends to the last row and column, which makes it hard to read. Replace the body with:
    Sub SelectUsedArea()
        ActiveSheet.UsedRange.Select
    End Sub
    UsedRange covers the rectangle from the first used cell to the last used cell, including blanks inside that rectangle.
  6. Select a contiguous data block. If your data sits in one solid island with headers, CurrentRegion is more precise than UsedRange because it stops at empty rows and columns:
    Sub SelectDataBlock()
        Range("A1").CurrentRegion.Select
    End Sub
    Change the anchor cell if your block does not start at A1.
  7. Select all cells on a specific sheet. Selecting a range on a non-active sheet raises run-time error 1004. Be explicit instead:
    Sub SelectAllOnSheet()
        Worksheets("Sheet2").Activate
        Worksheets("Sheet2").Cells.Select
    End Sub
    The Activate line is what makes the later selection legal.
  8. Select the same range on every sheet. To process all tabs, loop them:
    Sub SelectOnEachSheet()
        Dim ws As Worksheet
        For Each ws In ActiveWorkbook.Worksheets
            ws.Activate
            ws.Cells.Select
            'do something here
        Next ws
    End Sub
    Note that only the last sheet stays selected when the loop finishes, because selection is a property of the active window, not of each sheet.
  9. Avoid selecting when you can. The fastest and most reliable pattern is to act on the range without highlighting it. Compare Range("A1:D10").Select followed by Selection.Font.Bold = True with the direct Range("A1:D10").Font.Bold = True. The direct version runs faster, does not disturb the user's view and works even when the sheet is hidden or the workbook is not visible.
  10. Handle the case where nothing is selected. If you must read from Selection, guard against the user having selected a chart or shape, which causes a type mismatch. Check with If TypeName(Selection) = "Range" Then before using it.
  11. Save as a macro-enabled file. Press Ctrl+S, choose Excel Macro-Enabled Workbook (.xlsm), and confirm. Without this, the code is lost the next time the file opens.

Common Mistakes

  • Calling .Select on an inactive sheet. This throws error 1004, "Select method of Range class failed". Activate the sheet first, or drop the selection entirely.
  • Confusing Cells with Range. Bare Cells means all cells; Cells(1, 1) means a single cell A1. Mixing them up is a frequent source of unexpected behaviour.
  • Assuming UsedRange is tight. Formatting a whole column or deleting content without clearing formats leaves the used range far larger than your visible data. Fix it by deleting unused rows and columns and saving, or by using CurrentRegion.
  • Selecting inside a With block incorrectly. Inside With Worksheets("Sheet1"), writing .Cells.Select still fails if that sheet is not active, because selection is a UI action.
  • Forgetting that selection needs the workbook visible. Macros run on hidden workbooks cannot select anything meaningfully, which is another reason direct range operations are preferred.
  • Leaving ScreenUpdating off. If you toggle it off for speed, remember to turn it back on, otherwise the screen stops refreshing after the macro ends.

Tips

  • Use Application.Goto Reference:=Worksheets("Sheet1").UsedRange to scroll a range into view instead of just highlighting it.
  • Combine selection with offsets to extend it, for example Range("A1").CurrentRegion.Offset(1, 0).Resize(CurrentRegion.Rows.Count - 1).Select to skip a header row, though direct manipulation with .Resize on the range object is cleaner.
  • Store your target sheet in a variable (Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Data")) so the code keeps working if the sheet is renamed or the active tab changes.
  • Bind frequently used macros to the Quick Access Toolbar via File > Options > Quick Access Toolbar (Windows) so you do not have to open the editor each time.
  • Turn on Option Explicit at the top of each module to catch misspelled variable names before they cause silent bugs.

Troubleshooting

Error 1004 on .Select: The sheet is not active, or the workbook is not the active workbook. Activate it first with Worksheets("Name").Activate, or rewrite the code to manipulate the range directly.

Error 424 "Object required": You likely referred to Selection when nothing was selected, or used a misspelled object name. Check that the range variable was set with Set.

The macro runs but nothing highlights: The code may have finished before you looked, or ScreenUpdating is still false. Add Application.ScreenUpdating = True at the end and step through with F8 to confirm each line executes.

Selection is enormous and slow: You selected the whole sheet rather than the data. Switch from Cells.Select to UsedRange.Select or CurrentRegion, and clear stray formatting from far-off rows.

Macro not listed in the Macros dialog: The code may be in a sheet module rather than a standard module, or the subroutine is declared Private. Move it to a normal module with Insert > Module, and check the file is saved as .xlsm.

Macros blocked: Check Trust Center settings under File > Options > Trust Center > Trust Center Settings > Macro Settings. Only enable macros from files you trust, and never lower these settings for downloads from unknown sources.

Frequently Asked Questions

What is the VBA equivalent of Ctrl+A?

Cells.Select on the active sheet. If the cursor is inside a data block, Ctrl+A selects ActiveCell.CurrentRegion first, so ActiveCell.CurrentRegion.Select matches that behaviour more closely.

How do I select all cells on every sheet at once?

You cannot, technically. Excel's selection belongs to the active window, so only one sheet's cells can be highlighted at a time. You can loop through sheets, but each new selection replaces the previous one. Use Worksheets.Select to group tabs, or process each sheet's cells in code without selecting.

Why does my macro stop with run-time error 1004?

Almost always because the code tries to select a range on a sheet that is not currently active, or on a hidden or protected sheet. Activate and unprotect it where appropriate, or avoid selecting altogether.

How do I select all cells except the header row?

Use Range("A1").CurrentRegion.Offset(1).Select. Offsetting by one row moves the block down one row and also shifts the size, so pair it with Resize if the exact row count matters.

Does selecting cells actually change anything in the workbook?

No. Selection only affects the visible highlighting and where typing goes. Changing values requires writing to the range, such as Range("A1:D10").Value = 0, which works whether or not the cells are selected.

Is there a limit to how many cells I can select in VBA?

You are bound by the worksheet limits, which are 1,048,576 rows by 16,384 columns on modern Excel. In practice, selecting or manipulating all of them in code is slow; work with the used range instead.