Excel

Cell Select / Unselect

Ease of Use

Easy

Version tested with

2000 

Submitted by:

lucas

Description:

Allows you to unselect or deselect a cell within a group of selected cells. 

Discussion:

Once a number of cells have been selected using the Shift and Control keys, Excel does not allow you remove a cell from that selection. This macro makes it possible to deselect any one of the selected cells from the group selection. I don't remember where I came across this but it has been very useful. I use it in my personal.xls so that it is available in all workbooks and runs from a custom button. 

Code:

instructions for use

			

Sub UnSelectActiveCell() Dim Rng As Range Dim FullRange As Range If Selection.Cells.Count > 1 Then For Each Rng In Selection.Cells If Rng.Address <> ActiveCell.Address Then If FullRange Is Nothing Then Set FullRange = Rng Else Set FullRange = Application.Union(FullRange, Rng) End If End If Next Rng If FullRange.Cells.Count > 0 Then FullRange.Select End If End If End Sub

How to use:

  1. Open the Visual basic editor by clicking on Tools-Macro-Visual basic Editor or by holding down the ALT key and pressing F11.
  2. Go to Insert on the menu and click on add new module
  3. Paste the code in the module window at right.
  4. Close the Visual Basic Editor to get back to Excel; save if desired.
  5. Go to tools-Macro-Macros and double-click UnSelectActiveCell.
 

Test the code:

  1. To use the procedure, select a bunch of cells, and with the CTRL key still down, make A4 (or whatever cell you want to remove) the ActiveCell.
  2. Then let up on the CTRL key and run the macro UnSelectActiveCell. This leaves all the cells other than the ActiveCell selected.
  3. Now, hold the CTRL key down and continue selecting cells.
 

Sample File:

unselect_one_cell.zip 7.35KB 

Approved by mdmackillop


This entry has been viewed 374 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express