Consulting

Results 1 to 3 of 3

Thread: Custom right-click menu

  1. #1
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location

    Question Custom right-click menu

    I have the following 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?.
    Thanks,

    Marcster.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Thanks Tony ,
    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.

    Marcster.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •