Setting selection to Nothing when programming Excel

后端 未结 17 1908
误落风尘
误落风尘 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:07

    Select any cell and turn off cutcopymode.

    Range("A1").Select
    Application.CutCopyMode = False
    
    0 讨论(0)
  • 2021-02-02 10:11

    If using a button to call the paste procedure,

    try activating the button after the operation. this successfully clears the selection

    without

    • having to mess around with hidden things
    • selecting another cell (which is exactly the opposite of what was asked)
    • affecting the clipboard mode
    • having the hacky method of pressing escape which doesn't always work

    HTH

    Sub BtnCopypasta_Worksheet_Click()
       range.copy
       range.paste
    BtnCopypasta.Activate
    End sub
    

    HTH

    0 讨论(0)
  • 2021-02-02 10:13

    I had this issue with Excel 2013. I had "freeze panes" set, which caused the problem. The issue was resolved when I removed the frozen panes.

    0 讨论(0)
  • 2021-02-02 10:16

    Just use

    SendKeys "{ESC}"

    thereby cancelling your selection.

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题