Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting selection to Nothing when programming Excel

Tags:

excel

vba

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 first series in the plot. I can delete the series, but is there a more elegant way to do this? I tried

Set selection = nothing 

but it won't let me set selection. I also tried selection.clear, but that just cleared the last cells that were selected, and still added an extra series to the plot.

like image 925
Curt Avatar asked Nov 15 '08 17:11

Curt


People also ask

How do you avoid selection in Excel VBA?

Probably the biggest thing you can do to avoid using Select is to as much as possible, use named ranges (combined with meaningful variable names) in your VBA code.

How do I stop Excel from prompting?

In Excel, select Edit Links in the Queries & Connections group on the Data tab. Click Startup Prompt. Click the Don't display the alert and don't update automatic links option.


2 Answers

Application.CutCopyMode = False 
like image 54
David Avatar answered Sep 20 '22 18:09

David


Cells(1,1).Select 

It will take you to cell A1, thereby canceling your existing selection.

like image 34
shahkalpesh Avatar answered Sep 20 '22 18:09

shahkalpesh