-
Custom right-click menu
I have the following code which needs amending:
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 1 Then Exit Sub 'Column A
If Target.Row = 1 Then Exit Sub 'Row 1
CommandBars("Custom_RightClickMenu").ShowPopup
Cancel = True 'Do not show the default rightClick menu
End Sub
The above code will show the 'Custom_RightClickMenu' when user
right clicks on any cell in Column A apart from cell A1.
Is there a way to use 'names' instead of
Target.Row and Target.Column?. :dunno
Thanks,
Marcster.
-
Hi Marcster,
You can't avoid using Target (you can call it what you want but you can't avoid using it) but you can compare it to a named range ..
Code:
If Intersect(Target, Range("MyNamedRange") Is nothing then exit sub
' Do you stuff here
Is that the sort of thing you mean?
-
Thanks Tony :thumb,
Yes, that was what I'm after.
Procedure now reads:
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("MyNamedRange")) Is Nothing Then
Exit Sub
End If
CommandBars("Custom_RightClickMenu").ShowPopup
Cancel = True 'Do not show the default rightClick menu
End Sub
Thread solved. :checkmark
Marcster.