VBA & Macro Problems

Insert Rows with an Office Script in Excel for the Web

Natalie TaylorNatalie Taylor Nov 18, 2026 868 views

Question details

The user wants to insert a row at a selected location in Excel for the web using a script and an optional button.

Insert Rows with an Office Script in Excel for the Web
Product
Microsoft Excel for the web
Device & OS
not provided
Scenario
A workbook user selects a cell and runs a script to insert a row above it.
Observed behavior
Excel for the web does not run VBA macros, so an Office Script can provide the row-insertion action instead.
Before you start

Open the workbook in Excel for the web and check that the Automate tab is available. Office Scripts availability depends on your Microsoft 365 account and organization settings.

Solution 1Recommended

Create an Office Script to Insert a Row Above the Active Cell

Use this script when workbook users need to insert a row at the active cell without running VBA.

1
Open the script editor

In Excel for the web, open the workbook, select the Automate tab, and choose New Script.

2
Enter the script

Replace the editor contents with: function main(workbook: ExcelScript.Workbook) { const selectedCell = workbook.getActiveCell(); selectedCell.getEntireRow().insert(ExcelScript.InsertShiftDirection.down); }

3
Save and test

Save the script with a descriptive name. Select a cell in the row where you want the new row inserted, then select Run in the script editor. A new row appears above the active cell.

4
Add a worksheet button

Open the saved script from Automate, then use its More options menu to choose Add button to worksheet. Users can select a cell and click the button to run the script.

Create an Office Script to Insert a Row Above the Active Cell
Access requirements: People running the script need the appropriate access to the workbook and Office Scripts. A button does not make VBA macros run in Excel for the web.
Free Microsoft Office alternative

Edit Excel Workbooks with WPS Spreadsheet

WPS Office is a free, lightweight Office alternative with a familiar interface and Excel format compatibility for an easy transition. Use WPS Spreadsheet for everyday workbook editing; it does not replace this Excel Office Script or fix Excel for the web.

Insert and edit worksheet rows through the spreadsheet interfaceOpen and edit Microsoft Excel XLSX and XLS filesNavigate a familiar spreadsheet interfaceUse a free, lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

Where does the Office Script insert the new row?

It inserts a row above the active cell. Select a cell in the target row before running the script or clicking its worksheet button.

Why can't I find the Automate tab?

Office Scripts availability depends on your Microsoft 365 account and organization settings. Check that you are signed in with an eligible account, or ask your administrator whether Office Scripts are enabled.

Can I run a VBA macro instead in Excel for the web?

No. Excel for the web cannot run VBA macros. Use an Office Script for this row-insertion task, or open the workbook in a desktop version of Excel to run supported VBA macros.

Can colleagues use the script button?

They can use it if they have the necessary access to the workbook and Office Scripts. Add the button from the saved script's More options menu in the Automate tab.