Forum Discussion
Unable to deselect in excel
This is my current build information.
Microsoft® Excel® 2016 MSO (Version 2209 Build 16.0.15629.20152) 64-bit
- Nothing_Left_to_LoseOct 03, 2022Brass Contributor
There is VBA code I wrote that "unselects".
You need a macro button on the QAT to call it ormy preferred method of adding an item to the Cell right-click menu to call it.
The code...
'---
Sub UnselectActiveArea()
On Error GoTo PoorChoice
Nothing Left to Lose
If (Not SheetIsReady) Then Exit Sub
Dim Rng As Excel.Range
Dim FullRange As Excel.Range
If Excel.Selection.Areas.Count > 1 Then
For Each Rng In Excel.Selection.Areas
If Application.Intersect(ActiveCell, Rng) Is Nothing Then
If FullRange Is Nothing Then
Set FullRange = Rng
Else
Set FullRange = Application.Union(FullRange, Rng)
End If
End If
Next
FullRange.Select
FullRange.Areas(FullRange.Areas.Count).Cells(1, 1).Activate
Else
Excel.Selection.Cells(1, 1).Select
End If
Set FullRange = Nothing
Exit Sub
PoorChoice:
Beep
End SubFunction SheetIsReady() As Boolean
Nothing Left to Lose
If (VBA.TypeName(Excel.Selection) = "Range") Then
SheetIsReady = (Not Excel.Selection.Parent.ProtectContents)
End If
End Function'---
'Nothing Left to Lose
https://1drv.ms/u/s!Au8Lyt79SOuhZw2MCH7_7MuLj04?e=sAwbHU
(free excel programs)