web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Delete table rows on t...
Power Automate
Suggested Answer

Delete table rows on table that wasn’t created in the flow

(1) ShareShare
ReportReport
Posted on by 28
Need a flow to automate weekly Excel file cleansing. The files have Tables with temporary data that is replaced each week with new data. The tables feed charts and pivots on other sheets. On Friday the tables are cleaned and on Monday new data is inserted.
 
This flow is to perform the Friday cleaning, which includes a cell update and deleting table rows. On some Data Tables all rows must be deleted, while also keeping the headers and table structure. Other Tables only require some rows be deleted, based upon a date in one of the columns.
 
Because the tables were not created within the flow, I don’t have an output variable to reference which table to delete rows on.
 
The cell update in flow lines 1-7 work perfectl.  I cannot figure out how to delete table rows. The actions attempting to get a Data Table aren’t picking up the correct variable. I tried using the Table Name from my Excel file, but none of the delete actions recognize it. 
 
The attached flow shows all the actions I tried.  How do I set a pre-existing table as a variable to be used in next steps? Which actions are best used in Desktop for getting the variable and deleting table rows? Is it best done in a cloud flow?
 
Any help is appreciated. 
 
 
 
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,433 Super User 2025 Season 2 on at
    Hi,
     
    to get better answers, this should have gone to the Desktop version, not the cloud version of flows.
     
    I cannot move it, but hopefully someone will see it :-)
  • kschuster1 Profile Picture
    28 on at
    Thank you, FLMike. Looks like i posted this to the incorrect forum. I'll consider this solved and post it elsewhere.
     
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at
     
    Try this flow design 
    The above piece of code deletes all the rows from table named Table1 which is present in Sheet1
     
     
    The above piece of code delete the rows whose date column has value >25-06-2024
     
    Excel file used for this
     
    Table1
     
    Table2 
    Note- please make sure that date column format is of text type else this method/code may not work sometimes due to datetime format issues. 
     
    Code can be found below
     
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\Nived\\Downloads\\sampledata.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    # deleting entire data from the table
    Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''Sheet1'''
    Excel.GetTableRange Instance: ExcelInstance TableName: $'''Table1''' IsPivot: False FirstColumnIndex=> FirstColumnIndex FirstRowIndex=> FirstRowIndex LastColumnIndex=> LastColumnIndex LastRowIndex=> LastRowIndex
    Excel.DeleteCells.DeleteCells Instance: ExcelInstance StartColumn: FirstColumnIndex StartRow: FirstRowIndex + 1 EndColumn: LastColumnIndex EndRow: LastRowIndex ShiftCellsDirection: Excel.ShiftCellsDirection.Up
    Excel.SaveExcel.Save Instance: ExcelInstance
    # delete based on dates
    Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''Sheet2'''
    Excel.GetTableRange Instance: ExcelInstance TableName: $'''Table2''' IsPivot: False FirstColumnIndex=> FirstColumnIndex FirstRowIndex=> FirstRowIndex LastColumnIndex=> LastColumnIndex LastRowIndex=> LastRowIndex
    Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: FirstColumnIndex StartRow: FirstRowIndex EndColumn: LastColumnIndex EndRow: LastRowIndex ReadAsText: True FirstLineIsHeader: True RangeValue=> ExcelData
    Variables.FilterDataTable DataTable: ExcelData FilterParameters: { ^['RULE', 'COLUMN', 'OPERATOR', 'VALUE'], [$'''''', 0, $'''GreaterThan''', $'''25-06-2024'''] } FilteredDataTable=> FilteredDataTable
    LOOP FOREACH row IN FilteredDataTable
        Excel.FindAndReplace.FindSingle Instance: ExcelInstance TextToFind: row[0] MatchCase: False MatchEntireCellContents: True SearchBy: Excel.SearchOrder.Columns FoundColumnIndex=> FoundColumnIndex FoundRowIndex=> FoundRowIndex
        Excel.DeleteRow Instance: ExcelInstance Index: FoundRowIndex
        Excel.SaveExcel.Save Instance: ExcelInstance
    END
    Excel.CloseExcel.Close Instance: ExcelInstance
    
     
    Hope it helps !
    Thanks & Regards,
    Nived N 
    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs
     Found my answer helpful? Please consider marking it as the solution!
     Your appreciation keeps me motivated. Thank you!

     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard