ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   BeforeRightClick event vs. Selection Change (https://www.excelbanter.com/excel-programming/419179-beforerightclick-event-vs-selection-change.html)

DennisB[_2_]

BeforeRightClick event vs. Selection Change
 
I have two events that fire when I change the active cell, a BeforeRightClick
and Selection Change. If I select a new cell by right clicking, the code for
the selection change fires. How do I stop the selection change event when I
right click?

Peter T

BeforeRightClick event vs. Selection Change
 
Private Declare Function GetAsyncKeyState Lib "User32" _
(ByVal vKey As Long) As Long


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If GetAsyncKeyState(2&) Then Exit Sub ' right mouse down

End Sub

declare the API function as Public and put it in a normal module if you want
to call it from multiple modules

Regards,
Peter T

"DennisB" wrote in message
...
I have two events that fire when I change the active cell, a
BeforeRightClick
and Selection Change. If I select a new cell by right clicking, the code
for
the selection change fires. How do I stop the selection change event when
I
right click?




DennisB[_2_]

BeforeRightClick event vs. Selection Change
 
Peter,

I learned something new! This worked great, thank you so much.

Dennis

"Peter T" wrote:

Private Declare Function GetAsyncKeyState Lib "User32" _
(ByVal vKey As Long) As Long


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If GetAsyncKeyState(2&) Then Exit Sub ' right mouse down

End Sub

declare the API function as Public and put it in a normal module if you want
to call it from multiple modules

Regards,
Peter T

"DennisB" wrote in message
...
I have two events that fire when I change the active cell, a
BeforeRightClick
and Selection Change. If I select a new cell by right clicking, the code
for
the selection change fires. How do I stop the selection change event when
I
right click?






All times are GMT +1. The time now is 05:03 PM.

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