Custom Right-Click Menu only works in table???

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi Folks

I have the following piece of code to create custom right click menu linked to macros.
I went to adapt it to work when i right clicked on cell b3 but it does not seem to work.

The only thing i have found is that it works on a range or single cell as long as it is within a named table, if i try to use it for any other cells it doesn't work.

I am fairly sure I have used it before ( not in a table ) and it worked but i cant find the spreadsheet to have a look what is different.

any ideas would be most welcome :)

VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _ Cancel As Boolean)
 Dim a As Object


 For Each a In Application.CommandBars("list range popup").Controls
 If a.Tag = "a" Then a.Delete
 Next a
 
 If Not Application.Intersect(Target, Range("d7:d100")) _
 Is Nothing Then
 With Application.CommandBars("list range popup").Controls _
 .Add(Type:=msoControlButton, before:=6, _
 Temporary:=True)
 .Caption = "Move Selected Cells"
 .OnAction = "Move_Selected_Cells"
 .Tag = "a"
 End With
 End If
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Application.CommandBars("list range popup") refers specifically to the Table context menu. You'd need the Cell commandbar for normal cells (there are actually two commandbars by that name).
 
Upvote 0
Solution
Hi

I changed it earlier to "cell" instead of range and it didn't work.

I have just tried that again and this time it worked!! :rolleyes:

thank you Rory (y)
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,337
Members
448,568
Latest member
Honeymonster123

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