Forum Discussion
Disable copy paste function without VBA code
How to protect or stop copy paste on drop down column but select from drop-down option enable and save the file, without VBA?
The following steps may help.
- Select all cells with drop down list in the worksheet you need to protect. Click Find & Select > Data Validation under Home tab.
- Right click on them and select Format Cells in the right-clicking menu. In the Format Cells popup, go to Protection tab and uncheck Locked box. Click OK.
- Go to Review tab and click Protect Sheet button. In the Protect Sheet popup, check Protect worksheet and contents of locked cells option and enter a password if needed. Click OK.
This way, you can protect your worksheet from copying or pasting but still allow users to select from drop-down options.
Hope I could help you with these information.
I know I don't know anything (Socrates)
But this still allows users to Paste though the validation is there.
- NikolinoDEOct 31, 2024Gold Contributor
So far I know…Excel doesn’t offer a native, non-VBA solution to fully disable copy-paste functionality or restrict drag-and-drop operations in specific cells while keeping drop-down lists intact.
That’s why I give some few alternative approaches, they don't completely solve the problem, but they could help. If not, please ignore these approaches.
- MarthurvinNov 01, 2024Copper ContributorUnfortunately, all of the steps mentioned I'd already implemented. I discovered that the actual issue was not her copy/pasting, but rather her clicking the bottom boundary of the cell and dragging it slightly. This was causing the cell to unmerge (despite it being protected and supposedly unable to have its formatting changed). When it unmerges like that, all references to the cell cease to exist. She knows the pw so she unprotects the sheet, remerges it, then tries to continue... but of course that doesn't cause the references to that cell to magically reappear. When it gets back to me, it *looks* fine b/c the spreadsheet is too big to eyeball the numbers, but when I actually go into the formulas her attempts to fix it have actually broken it further (and hidden the problem). I've gotten her to stop trying to fix it but the issue of her dragging that bottom boundary enough to un-merge it remains.
- NikolinoDENov 02, 2024Gold Contributor
Example: Protect Critical Cells and Restore Them if Altered
This Office Script example monitors a range or individual cells for any changes and restores them to their original state if they are edited. It is useful for protecting formulas and important values.
function main(workbook: ExcelScript.Workbook) { // Define the worksheet and the critical range to monitor let sheet = workbook.getWorksheet("Sheet1"); // Update "Sheet1" to your actual sheet name // Define a range of cells to protect let protectedRange = sheet.getRange("A1:A10"); // Adjust as needed // Define the correct values or formulas for each cell in the protected range // This is hardcoded here for simplicity but can be customized for each cell let expectedFormulas = [ "=SUM(B2:B10)", "=AVERAGE(B2:B10)", "100", "200", "=B2*2", // Example formulas/values "", "", "", "", "" ]; // Loop through each cell in the range and check for changes for (let i = 0; i < protectedRange.getCellCount(); i++) { let cell = protectedRange.getCell(i, 0); // Get cell in the range let expectedFormulaOrValue = expectedFormulas[i]; // If the formula or value is incorrect, restore it if (cell.getFormula() !== expectedFormulaOrValue && cell.getValue() !== expectedFormulaOrValue) { // Reset the formula or value as needed if (expectedFormulaOrValue.startsWith("=")) { cell.setFormula(expectedFormulaOrValue); // Restore formula } else { cell.setValue(expectedFormulaOrValue); // Restore static value } } } // Inform the user that the protected range has been checked and any incorrect values have been restored workbook.getApplication().showAlert("Protected cells were checked, and any unintentional changes were corrected."); }
This script:
- Monitors a specified range or list of cells.
- Restores each cell to its expected formula or value if any unauthorized changes are detected.
1. Creating a Separate Script to Apply and Remove Sheet Protections
While you can't use Office Scripts to password-protect a sheet directly, you can create an automated workflow in Excel for the web by adding options that reset certain areas or formulas on demand.
2. Using Data Validation with Office Scripts for Indirect Protection
Data validation rules combined with Office Scripts can help protect input cells by ensuring that only expected values are entered. For example, a script could periodically check cells against data validation rules or apply validation rules to prevent specific input types.
Limitations of Office Scripts vs. VBA for Protection
- No Password Protection: Office Scripts cannot set or enforce passwords for sheet protection.
- No Direct Interception of User Actions: Office Scripts lack event-driven triggers (e.g., “on change”) that automatically run in response to user actions.
- Only Available in Excel for the Web: Scripts must be run manually unless combined with Power Automate, which enables automation but with limitations in real-time responsiveness.
For highly sensitive or critical workbooks, traditional Excel protections and VBA remain stronger options in the desktop version of Excel.