There is no "unselect" command in Excel VBA. Excel always keeps an active cell inside a selection, so you cannot have zero cells selected. What you can do is make the selection look and behave as if nothing is highlighted: shrink the selection back to a single cell, move the active cell somewhere harmless, or clear a previously made selection with Selection.Cut / Application.CutCopyMode = False if the highlight you are seeing is a dotted "marching ants" copy border rather than a real selection. The one-line fix for a real selection is ActiveCell.Select (or Range("A1").Select), which collapses the highlighted block to a single cell.
What You'll Need
- A copy of Excel for Windows or Mac with the Developer tab visible (File > Options > Customize Ribbon > tick Developer, or Excel > Preferences > Ribbon & Toolbar on Mac).
- A workbook saved as .xlsm if you want to keep your code, since a standard .xlsx will not store macros.
- Basic familiarity with the Visual Basic Editor (Alt+F11 on Windows, Option+F11 on Mac). Labels in the ribbon can differ slightly between versions, platforms and regions.
- Knowledge of whether your "unselected" problem is a selected range, a copied range (dotted border), or a shape/chart that is still selected - each has a different fix.
Step-by-Step
- Identify what is actually selected. Click once on any cell and look at the Name Box to the left of the formula bar. If it shows something like
A1:D20, a range is selected. If the border is a moving dotted line, the range has been copied, not just selected, and that is what you need to clear. If handles appear around a picture or chart, an object is selected. - Open the Visual Basic Editor. Press Alt+F11 (Windows) or Option+F11 (Mac). In the Project pane, double-click the module or sheet you want to edit. To test quickly, use the Immediate Window (Ctrl+G) so you can run one line at a time.
- Collapse a real selection with
ActiveCell.Select. In the Immediate Window typeActiveCell.Selectand press Enter. The highlighted block shrinks to the single active cell, which is as close to "nothing selected" as Excel allows. If you would rather land on a predictable cell, useRange("A1").Selectinstead. - Clear a copied range. If you see the dotted border, type
Application.CutCopyMode = Falsein the Immediate Window. This removes the copy or cut state completely. It also stops Excel from re-pasting the same range the next time someone presses Enter or Ctrl+V. - Unselect objects. If a shape, chart or button is selected, use
ActiveSheet.Shapes.Range(Array()).Selectto clear the shape selection, or simplyRange("A1").Selectto put the focus back on a cell. For charts,ActiveSheet.ChartObjects(1).Chart.Parent.Selecttype calls are unnecessary - reselecting a cell is enough to drop chart focus. - Put it into a macro. In a standard module, write something like:
Sub ClearSelection()Application.CutCopyMode = FalseActiveCell.SelectEnd Sub
Run it with F5. This clears any copy border first, then collapses the selection. - Reset selection after your own code. Macros that select and process ranges often leave the last range highlighted. Add the same two lines at the end of such routines so the sheet looks tidy when the user gets control back. If the macro turned off screen updating, switch it back on with
Application.ScreenUpdating = Truebefore the final select. - Consider not selecting at all. Most VBA tasks do not need
Select. Instead ofRange("A1:D20").Selectfollowed bySelection.Copy, useRange("A1:D20").Copy Destination:=Range("F1"). Working directly with ranges is faster and leaves the user's selection untouched, which avoids the problem entirely. - Handle the sheet-protection case. If
ActiveCell.Selectraises an error, the sheet may be protected or the active cell may be locked. Unprotect first withActiveSheet.Unprotect Password:="yourpassword", then re-protect at the end. Never hard-code a password in a workbook you share. - Test with several starting states. Select a large block, copy something, select a shape, then run the macro each time. Confirm the Name Box shows a single cell and no dotted border remains. Save the file as .xlsm.
Common Mistakes
- Looking for
Selection.Unselect. It does not exist. The Selection object has no such method, and typing it produces a compile or run-time error. - Confusing "copied" with "selected".
ActiveCell.Selectdoes not remove the dotted copy border. UseApplication.CutCopyMode = Falsefor that. - Calling
Selecton a range that is not on the active sheet. You get run-time error 1004. Activate the sheet first withWorksheets("Sheet1").Activate, or avoid Select entirely. - Leaving ScreenUpdating off. If a macro is interrupted after
Application.ScreenUpdating = False, the window can appear frozen. Re-run a small macro that sets it back to True. - Assuming a selection change is needed to clear the status bar message. It is not; use
Application.StatusBar = Falseto restore the default display. - Forgetting that some methods need the sheet active.
ActiveCellrefers only to the active sheet's cell, so an unqualified call can act on the wrong sheet in a multi-sheet workflow.
Tips
- Use the Immediate Window for one-line experiments before building a full macro - it shows errors instantly.
- Store a helper routine in your Personal Macro Workbook so "clear the selection" is available in every file.
- Assign the macro to a keyboard shortcut through Developer > Macros > Options, choosing a combination that does not clash with Excel defaults.
- When writing new code, prefer
Rangeobjects overSelection. It reads better, runs faster and never leaves stray highlights. - If you need the user to see a single active cell at the end of a routine, also reset
ActiveWindow.ScrollRowandScrollColumnso the view returns to the top-left area.
Troubleshooting
The highlight will not go away. Check the Name Box. If it shows a range, the code is not running or is running on another sheet. Confirm the module is a standard module and that macros are enabled in the Trust Center.
The dotted border returns. Something is still on the clipboard, or another macro copied again. Clear CutCopyMode as the very last line of the routine, after all copying is done.
Run-time error 1004. Usually a protected sheet, a hidden sheet, or a range reference on an inactive sheet. Activate the sheet, unprotect it if needed, and qualify your references.
Nothing happens at all. The macro may be stored in ThisWorkbook or a sheet module but written as a worksheet event procedure. Move the code to a standard module, or trigger it from a button.
The selection clears but the cursor jumps somewhere odd. Replace ActiveCell.Select with an explicit cell reference such as Range("A1").Select.
Frequently Asked Questions
Can I truly deselect all cells in Excel?
No. Excel requires at least one active cell on the active sheet. The closest behaviour is collapsing the selection to a single cell with ActiveCell.Select or Range("A1").Select.
Why does the dotted line stay after I run my macro?
That line means a range is on the clipboard. Add Application.CutCopyMode = False at the end of the macro to remove it.
Does this work on Excel for Mac?
Yes. The same ActiveCell.Select and CutCopyMode statements work, though the keyboard shortcuts differ: Option+F11 opens the editor.
Can I unselect a cell without VBA?
Yes, manually. Press Escape to cancel a copy, or click a single cell to collapse the highlight. There is no ribbon command that clears a selection.
Will this slow down my workbook?
Two lines at the end of a routine have a negligible effect. The bigger speed gain comes from removing Select and Selection from loops entirely.
Does it work on a protected sheet?
Selecting is usually allowed, but changing the active cell can fail if the sheet is protected with certain options. Unprotect, run the code, then protect again.