how to deselect selected Ranges

bestox

Board Regular
Joined
Apr 2, 2009
Messages
82
i use an excel workbook with several excel sheets. after running a makro, some ranges in some sheets are selected.

how can i deselect them? (due to optical reasons)

This does not work:

- Application.Goto Reference:=Worksheets("Tabelle1").Range("A1")
- Application.CutCopyMode = False

Thanks a lot!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You could:
1. Change your macro so that it doesn't select anything, which is good practice and more efficient (it is rarely necessary to select anything in code)
2. You could loop each sheet, selecting it and and selecting a specific cell.
 
Upvote 0
The general rule is that it's almost never necessary to actually select cells as part of running a macro but if you have to and want to just end with one selected then:

Code:
Worksheets("Sheet1").Activate
Range("A1").Select
Application.CutCopyMode = False

Should do the trick.

Dom
 
Last edited:
Upvote 0
@Dom

Have tried yours, but other ranges (in other sheets of the workbook) are still selected. any idea why this is?
 
Last edited:
Upvote 0
bestox,

Please post your macro code with code tags.


At the beginning of your posted code, enter the following without the quote marks:
["code"]


Your code goes here.


At the end of your posted code, enter the following without the quote marks:
["/code"]


Have a great day,
Stan
 
Upvote 0
@Dom

Have tried yours, but other ranges (in other sheets of the workbook) are still selected. any idea why this is?

Dom's code is just dealing with Sheet1. To do it for all worksheets, try:

Code:
Sub Test()
 
Worksheets.Select
Range("A1").Select
Worksheets(1).Select
End Sub

Remark: as you have already read, using select in vba is usually not necessary, just makes the code less efficient and more difficult to read.
You may consider the option to go back to your code and change it.
 
Upvote 0
Dom's code is just dealing with Sheet1. To do it for all worksheets, try:

Code:
Sub Test()
 
Worksheets.Select
Range("A1").Select
Worksheets(1).Select
End Sub

Remark: as you have already read, using select in vba is usually not necessary, just makes the code less efficient and more difficult to read.
You may consider the option to go back to your code and change it.


i ll do so next time.

your advice works, thank s a lot!

SOLVED!
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,840
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top