Showing popup menu only when EntireRow is selected

tweedle

Well-known Member
Joined
Aug 1, 2010
Messages
1,559
Sooo, I have my pop-up menu popping on BeforeRightClick, and I have suppressed the 'normal' context popup; How can I test to know that the user has selected a single entire row? That's really the only time I want the custom menu to display. The menu items are rather dedicated to replicating/producing entire rows within a project management template.

Below are my failed attempts....

Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
'    If ActiveSheet.Selection.EntireRow Then 'nope
'    If TypeName(Selection) = "Range" Then 'no
'    If Selection.Rows.Count > 0 Then    'not working
    If Selection.EntireRow.Count > 0 Then    'not working
    
    ShowMyMenu    'Shows my menu
    Cancel = True    'Suppresses the 'normal' context menu
    
    End If
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
maybe
Code:
if selection.columns.count=1 and selection.rows.count=rows.count then 'must be an entire column
 
Upvote 0
Code:
If selection.Rows(1).Cells.Count = Columns.Count then
 
Upvote 0
Both suggestions work, Thank You!!

Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    'If Selection.Rows.Count = 1 And Selection.Columns.Count = Columns.Count Then    'must be an entire column
    If Selection.Rows(1).Cells.Count = Columns.Count Then
        ShowMyMenu    'Shows my menu
        Cancel = True    'Suppresses the 'normal' context menu
    End If
End Sub

Rory, your signature line is hysterical
 
Upvote 0
If your intent is showing custom menu when ONLY one row is selected then this should work:
Code:
[face=Calibri][COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_BeforeRightClick([COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Range, Cancel [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Boolean[/COLOR])
[COLOR=darkblue]With[/COLOR] Selection
    [COLOR=darkblue]If[/COLOR] .Rows.Count = 1 And .Count = Columns.Count [COLOR=darkblue]Then[/COLOR]
[COLOR=green]    ShowMyMenu    'Shows my menu[/COLOR]
    Cancel = [COLOR=darkblue]True[/COLOR]    [COLOR=green]'Suppresses the 'normal' context menu[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
End [COLOR=darkblue]Sub[/COLOR][/face]
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,699
Members
453,747
Latest member
tylerhyatt04

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top