Range delete: You cannot perform the requested operation. Error

Andriii 25 Reputation points
2023-06-02T17:14:16.7366667+00:00

Hi, I have an Office Script that was working fine for several month. From 1 Jun it stopped working giving me an error.

Range delete: You cannot perform the requested operation.

The script was deleting all rows after a certain one.

There was the same error at another part of the script, but I've fixed it with

  workbook.getProtection().unprotect()



but that fix does not work here:

let balanceSheetRow = cell.getRowIndex();

  
  for (let i = rowCount - 1; i >= balanceSheetRow + 1; i--) {

    usedRange.getCell(i, 0).getEntireRow().delete(ExcelScript.DeleteShiftDirection.up)

  }
Microsoft 365 and Office Excel For business Windows
{count} votes

2 answers

Sort by: Most helpful
  1. Andriii 25 Reputation points
    2023-06-05T13:06:01.16+00:00

    try this:

    function main(workbook: ExcelScript.Workbook) {
        let selectedSheet = workbook.getActiveWorksheet();
        
        // Unprotect range A1:B10 on selectedSheet
        let rangeToUnprotect = selectedSheet.getRange("A1:B10");
        rangeToUnprotect.unprotect();
        
        // Insert at range 2:2 on selectedSheet, move existing cells down
        selectedSheet.getRange("2:2").insert(ExcelScript.InsertShiftDirection.down);
        
        if (selectedSheet.hasAutoFilter()) {
            selectedSheet.getAutoFilter().remove();
        }
    }
    
    
    1 person found this answer helpful.

  2. Tyler Kortmeyer 5 Reputation points
    2023-06-08T01:59:17.32+00:00

    https://learn.microsoft.com/en-us/answers/questions/1295289/broken-excel-script-please-help-me-troubleshoot

    This other question posted seems relevant to the issues discussed here. According to a Microsoft employee who responded, the issue has been identified today and a fix will be coming in the next few days. I would suggest following that question for further updates.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.