Forum Discussion

gmj12345's avatar
gmj12345
Iron Contributor
Nov 07, 2023

CLEAR MULTIPLE SHEET CELL

Is it possible to clear multiple cells in different sheets at the same time like just pressing a button or something?

 

How to do that?

 

I am using SharePoint M365 Business Basic by the way 🙂

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    gmj12345 

    Maybe this code will help you a little further in your project.

    function main(workbook: ExcelScript.Workbook) {
      // Define an array of sheet names and cell addresses to clear
      const cellsToClear = [
        { sheetName: "Sheet1", cellAddress: "A1" },
        { sheetName: "Sheet2", cellAddress: "B5" },
        { sheetName: "Sheet3", cellAddress: "C10" }
        // Add more sheet and cell combinations as needed
      ];
    
      // Loop through the array and clear the specified cells in each sheet
      for (const cellInfo of cellsToClear) {
        const sheet = workbook.getWorksheet(cellInfo.sheetName);
        const cell = sheet.getRange(cellInfo.cellAddress);
        cell.clear(ExcelScript.ClearApplyTo.contents);
      }
    }

    Code is untested...im not sure if this can work,It also depends on which sharepoint it is, please backup your file before.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

     

    Was the answer useful? Mark as best response and like it!

    This will help all forum participants.

     

Resources