Setting selection to Nothing when programming Excel

后端 未结 17 1864
误落风尘
误落风尘 2021-02-02 09:35

When I create a graph after using range.copy and range.paste it leaves the paste range selected, and then when I create a graph a few lines later, it uses the selection as the f

17条回答
  •  离开以前
    2021-02-02 10:17

    None of the many answers with Application.CutCopyMode or .Select worked for me.

    But I did find a solution not posted here, which worked fantastically for me!

    From StackExchange SuperUser: Excel VBA “Unselect” wanted

    If you are really wanting 'nothing selected`, you can use VBA to protect the sheet at the end of your code execution, which will cause nothing to be selected. You can either add this to a macro or put it into your VBA directly.

    Sub NoSelect()
       With ActiveSheet
       .EnableSelection = xlNoSelection
       .Protect
       End With
    End Sub
    

    As soon as the sheet is unprotected, the cursor will activate a cell.

    Hope this helps someone with the same problem!

提交回复
热议问题