Generally, we can deselect the cells from the selection range using the CTRL-key. If you want to do this with a single click, then this article might be helpful to you. Because we come up with the clear-cut steps to deselect cells from selected range using Macros (VBA) in Excel Office 365. Let’s get into this article!!
Deselect Cells from Selected Range:
For deselecting one or multiple cells in the range, do as follows.
- For example, you can see the input values in the Excel worksheet from the given image.
- On the Developer Tab, select the Visual Basic option under the Code section.
- Then you need to copy and paste the code given below.
VBA code to deselect cells using Macros
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
- You need to save the code by selecting it. Then close the window.
- You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.
- You need to make sure that your macro is selected and click the Run button.
- Then you need to select the one range where you want to deselect cells.
- You have to click the OK button.
- Now, you need to select one cell or multiple cells that you want to deselect.
- Then, hit the OK button.
- Finally, you will get the result as shown in the below image.
A Short Summary:
In the above article, you can easily learn how to deselect cells from a selected range using Macros (VBA) in Excel Office 365 with clear-cut steps. Kindly, drop your feedback in the below comment section. Thanks for visiting Geek Excel. Keep Learning!
Top comments (0)