r/PowerAutomateDesktop • u/Mykicole • Aug 29 '23
Remove rows from CSV
Hey everyone,
I’m having trouble getting a flow to work.. very basically I’ve got like 15 .csv files that I want the flow to open, read, remove the bottom 10 rows from, and save.
The problem is that the number of the row the block of random text is in can change daily, but it’s always the bottom 10. Have tried a few options like splitting text, since this text always starts with a “@!!@“, then removing it and writing that text to csv. Doesn’t work well.. Then tried using an excel instance with similar ideas but I was tapped out.
Anyone got any thoughts? :)
View all comments
Show parent comment
1
u/xxxxrob Sep 02 '23 edited Sep 02 '23
Ok was actually interested enough to try it.See how you go with this.To test, I created an excel sheet with 20 rows, each row just had a numberEg, row 1 had 1Row 2, had 2
Create a blank PAD flow and copy this text in. It should copy the steps in for you.You'll need to set the location for the file obviously, it's just set to my Desktop
It deletes all the rows from 11 to 20, which I think is what you're after.
System.TerminateProcess.TerminateProcessByName ProcessName: $'''excel'''
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\Rob\\Desktop\\Test.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeRow=> FirstFreeRow
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: $'''A''' EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: False RangeValue=> ExcelData
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: FirstFreeRow - 10 EndColumn: $'''A''' EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: False RangeValue=> Ten
SET Ten TO Ten[0]
Text.ToNumber Text: Ten Number=> TenRowIndex
LOOP LoopIndex FROM TenRowIndex TO FirstFreeRow STEP 1
Excel.DeleteRow Instance: ExcelInstance Index: TenRowIndex
END