Double click check event for row header

So, I'm pretty familiar with worksheet ranges for worksheets like double click. In this case, however, I'm looking for a link when the row header gets double clicked and not the cell. This would still be typical for a worksheet, but so far I have not been successful.

I have multiple ranges that execute different events on double click, so I am using code similar to the example below:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim rWatchRange As Range
    Dim sWatchRange As Range

    Set rWatchRange = Range("A5:A1000")

    'I somehow need it to recognize if the row header is 
    'double clicked between row 5 and 1000 to fire off the second sub

    Set sWatchRange = Range("5:1000")


    If Not Application.Intersect(Target, rWatchRange) Is Nothing Then
        Run "aFormattingSub"
    End If

    If Not Application.Intersect(Target, sWatchRange) Is Nothing Then
        Run "aSubToInsertNewLineAndGroupWithRowAbove"
    End If      
End Sub

      

I'm not sure if there is a desktop reference, an application reference, or an option in Excel that I know it can do.

+3


source to share


1 answer


DoubleClick event does not fire when double-clicking headers. I don't think there is a trivial way around - you have to live with events when they are presented.

I think there is still enough room to implement more functionality.
To give you a few more ideas, you can do different things by double-clicking or right-clicking while holding down the Ctrl key.

An example that responds to a right-click while holding down the Ctrl key and only when whole lines are selected:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    If (GetKeyState(KeyCodeConstants.vbKeyControl) And &H8000) And _
        Selection.Address = Selection.EntireRow.Address Then

        Cancel = True
        ' ... code
    End If
End Sub

      



( And &H8000

need to react only to the current one and ignore previous keystrokes)

Import API function into module:

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

      

+3


source







All Articles