PDA

View Full Version : Solved: Custom right-click menu



Marcster
12-02-2005, 06:30 AM
I have the folowing code which needs amending:

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.

TonyJollans
12-02-2005, 07:35 AM
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 ..

If Intersect(Target, Range("MyNamedRange") Is nothing then exit sub
' Do you stuff here

Is that the sort of thing you mean?

Marcster
12-02-2005, 07:43 AM
Thanks Tony :thumb,
Yes, that was what I'm after.

Procedure now reads:

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.