Reputation: 3325
I want to clear unselect the current selection whenever the user starts "MyMacro".
I'm using the following code:
Sub MyMacro()
If Not IsSheetExists("Memory") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).name = "Memory"
End If
Sheets("Memory").Visible = xlSheetVisible 'change to xlSheetVeryHidden
ActiveWorkbook.Sheets("Sheet1").Activate
ClearAllSheets
'......
End Sub
Sub ClearAllSheets()
For Each sh In ActiveWorkbook.Sheets
sh.Cells.Clear
sh.Buttons.Delete
Selection.Clear
Next sh
End Sub
Why doesn't Selection.Clear
clear unselect the current selection?
Upvotes: 2
Views: 55529
Reputation: 9
Try this
Application.CutCopyMode = False
it works for me
best regard
Upvotes: -1
Reputation: 19727
Selection.Clear
doesn't work since you don't have any selected range.
if you code it like this:
sh.Cells.Select
Selection.Clear
Then it will probably work.
But it is preferable not to use Select
.
Update: add this:
Dim rng as range
Set rng = Selection
or in your case:
set rng = sh.Application.Selection
then execute:
Selection.Clear.
it will clear the currently selected range.
Upvotes: 1
Reputation: 1335
Alright,
.Clear
is meant to clear the contents (& formatting) inside a cell/range, but not unselect
therefore, when you use Selection.Clear
, nothing happens
As you have mentioned also, why not just select a dummy cell?
Upvotes: 5