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.
Table of Contents
1. 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:
Step1: 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](https://www.excelhow.net/wp-content/uploads/2017/11/Get-the-position-of-the-nth-using-excel-vba1.jpg)
Step2: then the “Visual Basic Editor” window will appear.
Step3: click “Insert” ->”Module” to create a new module.
![convert column number to letter3](https://www.excelhow.net/wp-content/uploads/2017/12/convert-column-number-to-letter3.jpg)
Step4: paste the below VBA code into the code window. Then clicking “Save” button.
![deselect cells from selected range1](https://www.excelhow.net/wp-content/uploads/2018/12/deselect-cells-from-selected-range1.gif)
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
Step5: back to the current worksheet, then run the above excel macro. Click Run button.
![deselect cells from selected range2](https://www.excelhow.net/wp-content/uploads/2018/12/deselect-cells-from-selected-range2.gif)
Step6: Select one Range that you want to deselect cells, such s:A1:D7
![deselect cells from selected range3](https://www.excelhow.net/wp-content/uploads/2018/12/deselect-cells-from-selected-range3.gif)
Step7: select one cell or range of cells that you want to deselect.
![deselect cells from selected range4](https://www.excelhow.net/wp-content/uploads/2018/12/deselect-cells-from-selected-range4.gif)
Step8: Let’s see the last result:
![deselect cells from selected range5](https://www.excelhow.net/wp-content/uploads/2018/12/deselect-cells-from-selected-range5.gif)
2. Video: Deselect Cells from Selected Range with VBA
This video will demonstrate you how to deselect cells from a selected range of cells with a VBA Macro in your worksheet.
Leave a Reply
You must be logged in to post a comment.