VBA: How can I disable some options from right-click context menu - excel

I need to
1) Disable all the following options from "Cells" right-click context menu
a. Paste options
b. Insert
c. Delete
d. Format Cell
2) Disable all the following options from "Columns" right-click context menu
a. Paste options
b. Insert
c. Delete
d. Clear Content
e. Format Cell
3) Disable all the following options from "Rows" right-click context menu
a. Paste options
b. Insert Copied Cells only (Not Insert)
c. Format Cell
4) Disable all the following options from "Rows" right-click context menu for a specific range of rows (e.g. Rows 1 to 3)
a. Insert
b. Delete
c. Clear Content
5) Disable all the following option from " Form control button " right-click context menu
a. Format Control
Appreciate any help

Here is a simple way to achieve what you want. For most of them you can use exactly what you see in the right click menu. For example for Insert, you see Insert....
Application.CommandBars("Cell").Controls("Insert...").Visible = True 'False
Similary for others. I have not found a way to disable Paste Options: or the icons in it. You can however disable the Paste Special under Paste Options: as I mentioned above using Paste Special...
Note: Well this is the least of your problems. Remember users can still use the Ribbon or shortcut keys to achieve those things which you disable ;)
Edit
Unfortunately doesn't work for me. Does it have anything to do with Tables? because cells are part of a table! – Afshin Davoudy 8 mins ago
Yes for that you have to use
Application.CommandBars("List Range Popup").Controls("Delete").Visible = False
BEFORE
AFTER
Afshin Davoudy: how can I disable options in "Column" context menue? or Rows? (From Extended Chat)
Use
Application.CommandBars("Column").Controls("Delete").Visible = False
Application.CommandBars("Row").Controls("Delete").Visible = False

Related

EXCEL Prevent range from being deleted

I want to be able to delete or add rows in Section A without moving Section B without protecting the sheet.
Is there a way to sort of 'freeze' all those columns so they won't move? so if the user just wants more columns they can just right click on a entire row to add, or delete
Help is appreciated!
Delete
Select exactly what you want to delete. Press Ctrl + - (Control and Minus Sign) or choose Delete... in a context menu. Choose Shift cells up in a pop-up menu.
Insert
Select the range to insert. Press Ctrl + + (Control and Plus Sign) or choose Insert... in a context menu. Choose Shift cells Down in a pop-up menu.
Answer to additional question
Is there a way to sort of freeze all those columns so they won't
move when the user wants more rows to add?
In general - no. But if you manage to convert the left side (A in your picture) into an Excel Table aka Excel List then you can operate with rows and columns inside of it.

How to create a increment order drag down formula in excel like AT3, AU3, AV3,AW3,

I simply want a formula for drag down increment order pattern like AS3,AT3...CZ3,DA3 for Microsoft Excel 2016
How to do this is described in https://www.pryor.com/blog/create-a-custom-autofill-series-in-excel/
Create your own AutoFill Series:
In a set of cells add the elements in your custom series in the right order.
Select the cells which contain the data you want to comprise your custom list.
Click the File tab.
Click the Excel Options button to open the Excel Options dialog box.
Click the Advanced button [A] and scroll to the bottom of the Advanced Options window.
Click the Edit Custom Lists button [B] to open the Custom Lists dialog box.
=ADDRESS(3,ROW()+46-10,4)
3 = is the 3 you want to be displayed
46 = the start column number (you get it with this formula: =column() )
-10 = the row number of your first cell with the desired value (AT3)
4 = skip the dollar sign

How to filter out multiple values assigned to a specific name in my filer column?

I need to create an Excel template with f.e following columns and data:
Example of an Excel Table
and so on. So my goal is to set up the filter in such a way, that when I choose A1 from A column, I can get all the related B,C and D values, like B1,C1,D1; B1.1,C1.1,D1.1;B1.2,C1.2,D1.2
With the normal filter I can only see B1,C1,D1 when I choose A1.
The only solution I came up with, is writing A1 in every row that has relevant B 1.x ,C 1.x and D 1,x. Then I can see all relevant stuff, but this solution is not the most effective one(especially when values inserted will be a small text, writing same sentences in each row makes it look a bit messy)
The Pivot Table also does not recognize B1.1 C1.1,D1.1; B1.2 C1.2,D1.2 as related to A1. Even when I copied A1 in every row, it still couldn't sort it correctly.
Can you please help me with these quesitons? Many thanks in advance!
Kamola.
Update: I created a following example for clarification, hope it will help a bit! Unfortunately I cannot share the Excel Sheet per Stack Overflow, so here is a screenshot of it:Example of the content
MANUAL APPROACH
In your example which is a Table but not a pivot table,
Highlight Column Problems in your table;
Press Ctrl+G on your keyboard to bring out the Go To window;
Click Special... button at the left corner of the window;
Select Blanks then click OK;
Do not alter anything, go to the formula bar and enter =A2, then hold Ctrl key and press Enter.
If you have done the above steps correctly, you should have column A filled with Problem IDs.
POWER QUERY APPROACH
FYI, if you are using Excel 2010 Professional Plus or later versions of Excel, you can add your data table to Power Query Editor, right click the column header of the first column and select Fill -> Down to quickly fill the column with all Problem ID.
PIVOT TABLE APPROACH
If you want to show row labels in each line in a pivot table (as mentioned in your post), click somewhere within the pivot table, go to Design tab in the Excel ribbon, click Report Layout and select Repeat All Item Labels.
Let me know if you have any questions. Cheers :)

How to make column A reappear after resizing a table?

I clicked the resize button for a table on Excel from A3:O10 to B3:O10, and the column A permanently disappeared.
I tried resizing it to its initial address but doesn't work.
Check your "Freeze Panes" and "Split" settings. I've 'lost data' behind some silly visual representations with these.
You can see that my Column A appears to be Column C because I moved the wrong quadrant in a way I didn't actually want.
A simple solution to unhiding column "A" is to select all rows and columns (CTRL + A) and then right click on any column. After you right click then select "unhide" from the right click drop down.

Create Excel VBA to delete specific text from cell in one column

I am trying to create an Excel VBA that would delete only a specific part of the cell in only one column.
In Column A, I have a directory values:
For example:
Directoryof K:\data\Admin\
What I would like to do is remove the "Directoryof" from all the cells in column A and leave only the remaining text that follows it.
To create a macro to perform the above follow the below steps:
Click the "Developer" tab on the top menu.
You will find an option "Record Macro".
Click the Record Macro ->
a. A dialog box appears, give your macro a name
b. Shortcut key (if you want) can give by pressing (shift and any key such as
letters)
c. Store macro in : This workbook (this allows your macro to run on this sheet).
Click on "Use Relative References".
Once you are done, just perform the delete operation ( by removing the portion you do not want) on one of the column so that the macro may record the process which you are performing.
Once done, below at the lowest pane you will find Stop Macro option (a small blue square box). Click it to stop the recording of the macro.
Now you are ready with a macro to replicate the same without you performing the operation.
Just goto any other column where you want to perform the operation and click on "Macro" option on the developer tab and then click on your created marco, and you will see the magic happen.
You could probably use regex to accomplish what you are going for. Regular Expressions are often used for finding patterns. If all of your follows the same format, you could break your strings apart into two capture groups with something like:
(.+)([A-Z]:\\.+)
https://regex101.com/r/uD4uJ0/2 <-- this will show you your capture groups
Edit: I updated this link, sorry, originally had the wrong one.
This here How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops will show you how to split up capture groups if you are interested.
You could use something like text to columns, fixed width, and split the columns after Directoryof and then copy/paste the values back into column A.
I'm not sure if there's a method to do this without a helper column without VBA. If you can afford to use a second column, you can also use =LEFT(Cell, # of characters) assuming that the part you want to strip off is always "Directoryof" and then copy/paste values back into column A.

Resources