How to Deselect Cells from Selected Range with VBA

This post will guide you how to deselect cells from a selected range of cells in your worksheet. How do I quickly deselect cells from a selected range of cells with VBA code in Excel.

Normally, if you want to deselect a cell or multiple cells from a selection, you just need to hold down the CTRL key and click on the cells you want to deselect. If you want to unselect a range of selected cells, you need to hold down the CTRL key and drag the range you want to deselect. This post will explain that how to deselect cells from a selection with VBA Macro quickly in Excel.

Deselect Cells from Selected Range with VBA


You can use an Excel VBA Macro to quickly achieve the same result of deselecting one or multiple cells from a selected range of cells. Just do the following steps:

#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module.

convert column number to letter3

#4 paste the below VBA code into the code window. Then clicking “Save” button.

deselect cells from selected range1

Sub DeSelectCells()
    Set myRange = Application.Selection
    Set myRange = Application.InputBox("Select one Range:", "DeSelectCells", myRange.Address, Type:=8)
    Set DeleteRng = Application.InputBox("select one cell or range of cells that you want to deselect", "DeSelectCells", Type:=8)
    Dim LastRange As Range
    
    For Each myCell In myRange
        If Application.Intersect(myCell, DeleteRng) Is Nothing Then
            If LastRange Is Nothing Then
                Set LastRange = myCell
            Else
                Set LastRange = Application.Union(LastRange, myCell)
            End If
        End If
    Next

    LastRange.Select

End Sub

#5 back to the current worksheet, then run the above excel macro. Click Run button.

deselect cells from selected range2

#6 Select one Range that you want to deselect cells, such s:A1:D7

deselect cells from selected range3

#7 select one cell or range of cells that you want to deselect.

deselect cells from selected range4

#8 Let’s see the last result:

deselect cells from selected range5

Video: Deselect Cells from Selected Range with VBA

Related Posts

Find and Replace Multiple Values

This post will guide you how to find and replace multiple values at once with VBA macro or using formula  in Excel. How do I make multiple find and replace in Excel. Suppose that you have a few cells containing ...

VBA Macro For VLOOKUP From Another Sheet

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

Comments

So empty here ... leave a comment!

Leave a Reply

Sidebar