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

Chewyhairball

Board Regular
Joined
Nov 30, 2017
Messages
205
Office Version
  1. 365
  2. 2016
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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,066
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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).
 
Solution

Chewyhairball

Board Regular
Joined
Nov 30, 2017
Messages
205
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,825
Messages
5,766,663
Members
425,367
Latest member
Boboka

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
Top