In this article, we will discuss the context menu (or right-click menu) in Excel, including 2 ways to open the context menu, how to add and remove commands with VBA, and how to fix the issues when context menu options do not appear.
Download Practice Workbook
What Is the Context Menu in Excel?
The context menu is a pop-up menu that offers shortcuts to commonly used Excel commands and features.
In a Windows environment, the context menu is accessed by right-clicking with the mouse. It displays commonly used commands such as:
- Copy: Copies the selected cells or range.
- Cut: Displays a dotted line around the selected cells and cuts them.
- Paste Special: Opens the Paste Special dialog.
- Format Cells: Formats the selected cell as a number, text, date, or time data.
- Delete: Deletes cell data.
- Filter: Opens Filter By options.
How to Open the Context Menu in Excel
Method 1 – Right Clicking to Display the Context Menu
Example 1 – Cell Context Menu
Right-click on cell D5 to display the Cell context menu.
Example 2 – Sheet Tab Context Menu
Right-click a sheet name to open the Sheet Tab context menu.
Example 3 – Quick Access Toolbar Context Menu
Right-click on the Quick Access Toolbar to show its context menu options.
Example 4 – Ribbon Bar Context Menu
Go to the Ribbon bar and right-click on it to open its context menu.
Method 2 – Using Shortcut Keys to Show the Context Menu
Press Shift + F10 to open the Cell context menu.
How to Add (and Remove) Custom Options to the Context Menu
To add a custom button to the context menu:
- Go to the Developer tab and click on Visual Basic.
- In the Visual Basic window, click on Insert >> Module to create a module box.
- Enter the below VBA code in the module box.
- Click Run to execute the code.
Sub AddContextMenuDeleteItem()
Dim cBar As CommandBar
Dim cBarCtrl As CommandBarControl
Set cBar = Application.CommandBars("Cell")
Set cBarCtrl = cBar.Controls.Add(Type:=msoControlButton)
With cBarCtrl
.Caption = "Clear Cell"
.OnAction = "DeleteCellContent"
End With
End Sub
Sub DeleteCellContent()
Selection.ClearContents
End Sub
In the Cell context menu, we now have a custom option named Clear Cell that deletes the data in the selected D5.
- To remove the custom button, run the below VBA code in the same way.
Sub Remove_Items_from_Context_Menu()
On Error Resume Next
CommandBars("cell").Controls("Clear Cell").Delete
End Sub
How to Fix When the Context Menu Goes Missing in Excel
If the context menu options do not appear due to opening up the file with code or for other reasons, we can fix it with VBA as follows;.
- Go to View in the Visual Basic window and click Immediate Window.
- In the Immediate Window, enter the following VBA code and press Enter:
Application.CommandBars("Cell").Reset
Things to Remember
- Update the .Caption and .On Action properties in the VBA code to change the name of the custom button in the context menu.
- Customizing the Context Menu is not done in the same way as customizing the Ribbon bar in Excel.
Frequently Asked Questions
- Is it possible to change the order of the options in the Context menu?
No, the order of options in the Context menu is predefined and cannot be directly modified. However, we can customize the context menu using the VBA code provided above and arrange the options in the desired order.
- What is the difference between the context menu and the shortcut menu?
The context menu and the shortcut menu are both pop-up menus that appear when you right-click on a cell or object in Excel. However, the context menu contains a wider variety of commands and functions, while the shortcut menu only contains the most commonly used commands.
<< Go Back to Excel Parts | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!