VBA & Macro Problems

How to Clear Multiple Ranges on Multiple Sheets in Excel Online

Algirdas JasaitisAlgirdas Jasaitis Nov 11, 2026 868 views

Question details

The user needs to clear specific ranges of data across multiple worksheets simultaneously in Excel Online.

How to Clear Multiple Ranges on Multiple Sheets in Excel Online
Product
Excel Online
Device & OS
not provided
Scenario
Automating the process of clearing specific data ranges across several sheets in a web environment where traditional macros are disabled.
Observed behavior
Excel for the web does not support VBA macros, requiring users to find an alternative method, such as Office Scripts, to automate the clearing of worksheet ranges.
Before you start

Ensure you are signed in to a Microsoft 365 business or educational account with the Automate tab enabled, as Office Scripts are not available for personal accounts.

Solution 1Recommended

Use Office Scripts to Clear Ranges Across Sheets

Since VBA is not supported in Excel Online, you can use Office Scripts (TypeScript) to automate clearing specific ranges on permitted worksheets.

Office Scripts provide a modern, web-compatible way to automate tasks in Excel Online. You can write a short TypeScript function to iterate through specific sheet names and clear designated areas.

1
Open the Code Editor

In Excel Online, navigate to the Automate tab on the ribbon and click on New Script to open the Code Editor pane.

2
Enter the Automation Script

Paste the following script into the editor: function main(workbook: ExcelScript.Workbook) { const sheets = workbook.getWorksheets(); const names = ["AUS", "DAL", "HOU"]; const range = "B11:I16, B19:I24, B27:I32, B3:I8"; for (const sheet of sheets) { if (names.includes(sheet.getName())) { sheet.getRanges(range).getAreas().map(area => area.clear(ExcelScript.ClearApplyTo.all) ); } } }

3
Customize Sheet Names and Ranges

Modify the 'names' array in the code to match the exact names of the sheets you want to clear. Update the 'range' variable with the specific cell references you need to empty.

4
Save and Run the Script

Click the Save script button, then click Run. The script will immediately clear the specified ranges on the selected worksheets.

5
Add a Button to the Worksheet (Optional)

To make the script easier to run, click the More options (three dots) menu in the Script Details pane and select 'Add button'. This places a clickable button directly on your worksheet.

Use Office Scripts to Clear Ranges Across Sheets
No Interactive Confirmation Dialog: Unlike traditional VBA, Office Scripts cannot display interactive confirmation prompts (e.g., 'Are you sure you want to clear these ranges?'). The script executes immediately when run.

Use WPS Spreadsheet for Full VBA Macro Support

If you rely heavily on VBA macros for automating tasks like clearing ranges and do not want to rewrite them into Office Scripts, WPS Office is an excellent desktop alternative. It provides robust, built-in VBA support, allowing you to run your existing macros seamlessly.

  1. 1. Download and Install WPS Office: Download WPS Office for free from the official website and install it on your computer.
  2. 2. Open Your Macro-Enabled Workbook: Launch WPS Spreadsheet and open your existing Excel file (.xlsm) containing your VBA macros.
  3. 3. Enable and Run Macros: Navigate to the Tools tab, click on Macros, select the macro designed to clear your ranges, and click Run. Your original VBA code will execute natively.
Natively supports traditional VBA macros (.xlsm) without requiring code conversion.Fully compatible with Microsoft Excel file formats, ensuring your workbooks open flawlessly.Includes interactive VBA dialog boxes and user prompts that web-based scripts lack.Free and lightweight, featuring a familiar tabbed user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why don't VBA macros work in Excel Online?

Excel for the web (Excel Online) does not support the execution of VBA (Visual Basic for Applications) macros due to browser security restrictions and the web-based architecture. Microsoft uses Office Scripts as the cloud-based automation alternative.

Who can run the Office Script if I share the workbook?

Any user who has been granted permission to edit the shared workbook can run the Office Script, especially if you have added a script button directly to the worksheet for easy access.

Can I undo the changes made by an Office Script?

While you can sometimes use the Undo function (Ctrl+Z) immediately after a script runs, it is not always reliable for large data operations. It is highly recommended to save a backup of your workbook before running scripts that clear or delete data.

Are Office Scripts available for personal Microsoft 365 accounts?

No, currently Office Scripts are only available for commercial or educational Microsoft 365 accounts with the Automate feature enabled by the organization's administrator.