Excel VBA has no "unselect" command, but you can deselect a range in practice by moving the selection somewhere harmless, such as a single cell like Range("A1").Select, or by temporarily hiding the selection highlight with Application.ScreenUpdating = False and setting ActiveCell where you want it. The cleanest solution, however, is to write code that avoids selecting anything at all, because most VBA operations work directly on Range objects without a selection. This guide covers both approaches: clearing or moving an existing selection, and refactoring code so nothing gets selected in the first place.
What You'll Need
- A workbook saved as a macro-enabled file (.xlsm), or a workbook where you are allowed to run macros
- The Developer tab visible in Excel (enable it via File > Options > Customize Ribbon if it is missing)
- Basic familiarity with opening the VBA editor (Alt + F11)
Step-by-Step
- Open the VBA editor. Press Alt + F11 in Excel. In the Project Explorer on the left, find your workbook and expand it to see its modules and sheets.
- Insert or open a module. Right-click your workbook in the Project Explorer, choose Insert > Module, or double-click an existing module where your code lives.
- Understand why there is no Unselect. In Excel's object model, exactly one range is always selected at any time. There is no
Range.UnselectorSelection.Clearfor deselection, so the practical goal is to park the selection on an innocuous cell instead. - Move the selection to a single neutral cell. Add this line where you want the selection "cleared":
Range("A1").Select(or any cell that will not distract the user). This is the standard substitute for an unselect command. - Select a cell without scrolling the view. If jumping to A1 scrolls the window away from where the user was working, first note the top-left visible cell, select A1, then scroll back. Example:
Dim addr As String: addr = ActiveWindow.VisibleRange.Cells(1,1).Address, thenRange("A1").Select, thenApplication.Goto Reference:=Range(addr), Scroll:=True. - Hide the selection highlight entirely (optional). For a truly invisible selection, you can shade the active cell to match, but the more common trick is simply to keep ScreenUpdating off while your macro runs:
Application.ScreenUpdating = Falseat the start andApplication.ScreenUpdating = Trueat the end, so the user never sees selections flashing around. - Avoid selecting in the first place. Replace recorded code like
Range("B2:B10").Selectfollowed bySelection.Copywith the direct equivalent:Range("B2:B10").Copy. Nearly every action (copy, delete, sort, format, assign values) works directly on a Range without selecting it. - Replace Selection with a Range variable. Instead of
Range("C5").Select/Selection.Value = 42, writeRange("C5").Value = 42. For repeated use, declareDim rng As Range, setSet rng = Range("C5"), then userng.Value = 42. - Restore the user's original selection when done. If your macro must select things internally, save and restore context:
Dim userSel As Range: Set userSel = Selectionat the top, thenuserSel.SelectandApplication.ScreenUpdating = Trueat the end so the user's view is unchanged. - Test the macro. Press F5 in the editor or run it from Developer > Macros. Confirm the sheet ends with the selection where you intended and no visual flicker during execution.
Common Mistakes
- Searching for a real Unselect method.
Selection.UnselectandRange.UnSelectdo not exist. Code using them throws a compile or runtime error. UseRange("A1").Selectinstead. - Forgetting to turn ScreenUpdating back on. If an error halts the macro before
Application.ScreenUpdating = True, Excel may look frozen. Put the reset in an error handler:On Error GoTo Cleanupand restore settings there. - Selecting on a non-active sheet.
Sheets("Data").Range("A1").Selectfails unless that sheet is active. Either activate the sheet first or, better, skip the Select entirely and act on the range directly. - Leaving ScreenUpdating off permanently by ending the macro early with
End(which skips cleanup). PreferExit Subafter your cleanup code rather thanEnd. - Confusing deselect with delete.
Selection.Clearerases cell contents; it does not deselect anything. Be careful which one you actually want.
Tips
- Macros that never select anything run noticeably faster on large datasets because Excel skips repainting the selection after each step.
- Recorded macros are the main source of unnecessary Select statements. After recording, rewrite every
.Select+Selection.pair into a single direct statement. - To deselect cells within a multi-area selection (Ctrl-selected cells), there is no VBA way to remove one area; reselect the areas you want to keep, e.g.
Range("A1:A5,C1:C5").Select. - Pair
Application.ScreenUpdating = FalsewithApplication.Calculation = xlCalculationManual(restored afterwards) in long loops for even bigger speed gains.
Troubleshooting
- "Method 'Range' of object '_Global' failed" or "Select method of Range class failed": you are selecting a range on a sheet that is not active, or the sheet is protected. Activate the sheet first or drop the Select call entirely.
- Excel looks frozen after running the macro: ScreenUpdating was left off. Run any small macro containing
Application.ScreenUpdating = True, or add proper error handling so cleanup always runs. - The screen flashes through many selections: leftover
.Selectcalls in your code. Remove them as shown in steps 7-8, or wrap the routine in ScreenUpdating off/on. - Compile error "Method or data member not found": you used a nonexistent Unselect method. Replace it with
Range("A1").Select. - Macros won't run at all: check that the file is saved as .xlsm and that macros are enabled (the security warning bar below the ribbon, or File > Options > Trust Center settings).
Frequently Asked Questions
Is there an Unselect method in Excel VBA?
No. Excel always has exactly one selected range, so VBA provides no way to have no selection at all. The workaround is to select a harmless cell such as A1.
How do I make the selection invisible to the user?
Set Application.ScreenUpdating = False while the macro runs, do your work, then restore it to True. The user never sees the selection moving. You can also select A1 on a protected, formatted sheet so the highlight is unobtrusive.
Why does my recorded macro select everything?
The macro recorder captures every click you make as Select statements. This is safe but slow; rewriting the code to act on ranges directly is standard practice and makes the deselect problem disappear.
Can I deselect one cell from a multi-area selection?
Not directly. You must rebuild the selection from the areas you want to keep and select that combined range in one statement.
Does avoiding Select really make macros faster?
Yes. Selection changes force Excel to repaint the screen and update the interface. Removing them typically speeds up loops and bulk operations substantially, especially combined with turning off ScreenUpdating.
How do I keep the user's original selection after my macro runs?
Save it at the start with Set userSel = Selection, then call userSel.Select just before the macro ends, making sure the correct sheet is active first.