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.
Step-1:
Select instant cloud flow, enter the flow name, choose the trigger as a manual trigger, and click the create option.
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
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.
Step-4:
Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:
Now we can see our Excel rows table data has been deleted.
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.
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.
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.
Step-3:
Save and run the flow by selecting the run flow option. Once the flow runs successfully, like below:
The screenshot below shows that our Excel rows data has been deleted.
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.
You may also like:
- Convert CSV to Excel using Power Automate
- Create an Excel file from SharePoint list items using Power Automate
- Import Data from Excel to a SharePoint list using Power Automate
- Create SharePoint site columns from an Excel file in Power Automate
- Move files from one folder to another using Power Automate
- How to use append to string variable action in Power Automate?
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.