Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Removing Cells from a Selected Range.

Removing Cells from a Selected Range

by Allen Wyatt
(last updated January 2, 2020)


Let's say that you've selected a large range of cells, such as A7:R182. You want to perform some sort of operation on all the cells in this range, except a few. You might wonder how to remove a couple of cells within the range from the selection set, so you hold down the Ctrl key as you click on those cells. That doesn't work; Excel simply unselects the range you previously selected.

There is no way to change this behavior within Excel itself. Instead, you need to turn to other solutions. One is to use a macro, such as the following:

Sub UnSelectSomeCells()
    Dim rSelect As Range
    Dim rUnSelect As Range
    Dim rNew As Range
    Dim rCell As Range

    Set rSelect = Selection
    Set rUnSelect = Application.InputBox( _
      "What cells do you want to exclude?", Type:=8)

    For Each rCell In rSelect
        If Intersect(rCell, rUnSelect) Is Nothing Then
            If rNew Is Nothing Then
                Set rNew = rCell
                Set rNew = Union(rNew, rCell)
            End If
        End If

    Set rCell = Nothing
    Set rSelect = Nothing
    Set rUnSelect = Nothing
    Set rNew = Nothing
End Sub

To use the macro, select the entire range you want to start with, such as A7:R182. Then run the macro. You are asked to choose the cells to be unselected. You can do so by simply selecting the cells with the mouse, holding down the Shift key as you click on each one. When you dismiss the input box, the selection you started with is modified to exclude the cells you selected.

If you prefer to not use your own macros, you can find help for deselecting cells in a selected range by using third-party tools, such as the ASAP Utilities. You can find their Excel tools at this Web page:

The tool applicable to this tip is the Select tool.


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12457) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Removing Cells from a Selected Range.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Changing the Color of a Cell Border

Excel provides a variety of tools you can use to make your data look more presentable on the screen and on a printout. ...

Discover More

Renaming a File

Need to rename a disk file from within a macro? You can do it using the Name command, described in this tip.

Discover More

Lines Breaking between Double Spaces

Some people like to have one space between sentences, while others prefer two. For those in the latter camp, you may ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Using the Fill Handle from the Keyboard

The fill handle can save a huge amount of time when you are editing a worksheet. If you are really good at using the ...

Discover More

Deleting Duplicate Columns

Have a worksheet in which there may be entire columns that are duplicates of each other? If you want to delete those ...

Discover More

Deleting Rows Containing Struck-Through Text

Excel makes it easy to delete rows in a worksheet, but it can be more difficult to figure how to delete rows if you only ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 4?

2020-01-02 09:59:30


This works in Excel on Mac and has worked since the dawn of time (i.e. when fist version of Excel was designed ... for Mac)

2020-01-02 07:20:33


Thanks to Allen and Willy, this is very useful!

2020-01-02 03:57:15

Russell Stainer

In the latest releases of Office365, you can now select a range of cells, and then unselect individual cells whilst holding the Ctrl key down.
The aggregated values in the footer of Excel change correctly, and you can perform operations on just the selected cells, like you would wish to (I only tried Bold and Centre, but they worked fine).

2014-08-11 11:05:21

Willy Vanhaelen

This is a very useful macro although it has a bug. When the input box is displayed and you click cancel you get an error. This can be fixed with: On Error GoTo ...

I like my macros always to be as compact as possible. So the three lines,

Dim rSelect As Range
Set rSelect = Selection
For Each rCell In rSelect

can be replaced with this one line:

For Each rCell in Selection

Two line less. Also, although setting the variables to Nothing at the end of the macro does no harm, it is pointless because when the macro ends, its variables are cleared automatically. Again four lines less.

Here is my compact version with the bug fixed:

Sub UnSelectSomeCells()
Dim rUnSelect As Range, rNew As Range, rCell As Range
On Error GoTo Canceled
Set rUnSelect = Application.InputBox("Cells to exclude...", Type:=8)
For Each rCell In Selection
If Intersect(rCell, rUnSelect) Is Nothing Then
If rNew Is Nothing Then Set rNew = rCell Else Set rNew = Union(rNew, rCell)
End If
End Sub

2014-08-11 11:02:28

Willy Vanhaelen

@Hanspeter: I tried it and functions do respond to the new range.

Make sure your user defined functions are in a module and recalculation is set to automatic.

2014-08-08 13:16:58


The above macro runs on Excel 2010, and the selected (and deselected) cells are marked out on the worksheet, but I can't find a way to actually get the new range to be used in a function. Hints?

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.