How to delete all rows in Excel using Power Automate?

In this Power Automate tutorial, we will see how to delete all rows in Excel using Power Automate with examples.

Scenario

Here I’ll show you two examples. In the first example, we will see how to delete all rows in the Excel file using the delete row flow action. In another example, we will learn to delete all rows presented in the Excel table by using an Office Script in Power Automate.

How to delete all rows in Excel using Power Automate

Let us see how to delete all rows in Excel using Power Automate.

Example -1: (Using Delete a row action)

In this example, we will use the below Employees Excel workbook, presented in the SharePoint online document library.

How to delete all rows in Excel using Power Automate

Step-1:

Select instant cloud flow, enter the flow name, choose the trigger as a manual trigger, and click the create option.

delete all rows in Excel using Power Automate

Step-2:

Select + new step and add a List rows present in a table action from action triggers; provide the below details:

  • Location – Select the location where the Excel workbook exists
  • Document Library – Choose the document library from the dropdown
  • File – Select the Excel workbook for which you want to delete the rows
  • Table – Select the table name from the dropdown
delete all rows in Excel using Power Automate flow

Step-3:

Add a delete a row action from an action trigger; provide the below details:

  • Location – Select the location where the Excel workbook exists
  • Document Library – Choose the document library from the dropdown
  • File – Select the Excel workbook for which you want to delete the rows
  • Table – Select the table name from the dropdown
  • Key – Enter custom value and pass the Emp ID column name
  • Values – Pass the dynamic content value of Emp ID. It will automatically create an apply to each control to loop and delete all the rows presented in the Excel workbook.
Example to delete all rows in Excel using Power Automate

Step-4:

See also  How to Change Trigger in Power Automate [3 Different ways]

Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:

How to delete all rows in Excel using Power Automate flow

Now we can see our Excel rows table data has been deleted.

Power Automate delete rows in excel

This is one way to delete all rows in Excel using Power Automate.

Example -2: (Using Office Script)

For this example, we will use the below Customers Excel workbook, presented in the SharePoint online document library.

Power Automate delete rows in excel using office script

Step-1:

  • Open the Excel workbook, select the Automate tab, and choose New Script. It will open the code editor and add the script code below to delete all Excel workbook rows.
function main(workbook: ExcelScript.Workbook) {
  let Table = workbook.getTable("Table1");
  let RowCount = Table.getRowCount();
  Table.deleteRowsAt(0, RowCount);
}

Once the code has been added, save the script.

Example to delete all rows in Excel using office script in Power Automate

Step-2:

Log in to Power Automate, and create an instant cloud flow with manual trigger action. Select + New step and add a Run Script action from action triggers.

  • Location – Select the location where the Excel workbook exists
  • Document Library – Choose the document library from the dropdown
  • File – Select the Excel workbook for which you want to delete the rows
  • Script – Select the created Script from the dropdown.
Example to delete all rows in Excel using office script in Power Automate flow

Step-3:

Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:

delete all rows in Excel using office script in the Power Automate

The screenshot below shows that our Excel rows data has been deleted.

Example to delete all rows in Excel using office script in the Power Automate

This is another way to delete all rows in Excel using Power Automate.

In this Power Automate tutorial, we saw how to delete all rows in Excel using Power Automate with examples.

See also  Create a Site column in SharePoint Online using Power Automate

You may also like:

>