ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Suppress Worksheet_SelectionChange conditionally (https://www.excelbanter.com/excel-programming/441687-suppress-worksheet_selectionchange-conditionally.html)

IanC[_2_]

Suppress Worksheet_SelectionChange conditionally
 
Is there any way to suppress Worksheet_SelectionChange in instances where
the selection change comes from a programmed command rather than user
action?

--
Ian
--



B Lynn B

Suppress Worksheet_SelectionChange conditionally
 
Application.EnableEvents = False

Insert just before the line of code that would otherwise trigger the event.
Make sure you always get it set back to True before code stops executing,
whether by error handler or before end/exit sub.

"IanC" wrote:

Is there any way to suppress Worksheet_SelectionChange in instances where
the selection change comes from a programmed command rather than user
action?

--
Ian
--


.


Tim Williams[_4_]

Suppress Worksheet_SelectionChange conditionally
 
You could try

Application.EnableEvents = False
'make your selection changes
Application.EnableEvents = True

Or, if you have access to the code, you could insert a check in your
Worksheet_SelectionChange code to check the value of a global variable
and exit without any action if required.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If DoNothing Then Exit Sub

'....other code here
End Sub



Tim




On Apr 15, 10:52*am, "IanC" wrote:
Is there any way to suppress Worksheet_SelectionChange in instances where
the selection change comes from a programmed command rather than user
action?

--
Ian
--



IanC[_2_]

Suppress Worksheet_SelectionChange conditionally
 
Many thanks to B Lynn B & Tim Williams.

Application.EnableEvents = False does exactly what I need.

--
IanC
--


"IanC" wrote in message
...
Is there any way to suppress Worksheet_SelectionChange in instances where
the selection change comes from a programmed command rather than user
action?

--
Ian
--






All times are GMT +1. The time now is 04:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com