How to Delete Last row in pivot table

Hi,
i have one excel i want to delete last row of pivot table without opening excel.

Screenshot 2024-06-14 150505

above attached my screen shot for you.

Regards,
Mohamed Farhan

Hi @MD_Farhan1

You can use the below syntax


(Excel.Sheet("Sheet1").DataTableValue.RowCount).ToString

Regards

Hi @MD_Farhan1

Use Find First/Last Row activity and then use delete rows activity

Regards,

Hi @MD_Farhan1

You can use the Excel activites to delete the last row in pivot tables.
→ Use the Excel Process scope activity and insert the Use excel file activity inside of it.
→ Inside Use excel file activity insert the Find first\last row activity, In the source field type the Excel. it will shows the pivot tables in that excel. select that pivot table.
Check the below one,

Excel.Sheet("Sheet name").PivotTable("Pivot Table Name")

→ Create a variable in the Save last row number as field to store the last row number in a variable.
→ Then use the delete row activity to delete the last row in Pivot table.

Open the Properties of Excel Process scope activity go to properties and select the false option for Show excel window property. It will not open the Excel in foreground.
image

Hope it helps!!

not working bro… any linq method to delete last row??

Yeah sure bro please give me 2mins

Regards

1 Like

@MD_Farhan1

Use Excel File : Provide path to your Excel file

-Read Range: Read pivot table data into a DataTable dtPivotTable.

-Assign: dtPivotTable to dtPivotTable.Rows.RemoveAt(dtPivotTable.Rows.Count - 1)

-Write Range: Write dtPivotTable back to the Excel file, overwriting the pivot table data.

HAPPY AUTOMATION!!

I got an error

Screenshot 2024-06-14 153949

Regards,
Mohamed Farhan

Hi @MD_Farhan1

Please check the below screenshot and vba code:

DeleteGrandTotalRow.txt (542 Bytes)

Regards

1 Like

Thank you Bro now its working fine :+1:

You’re welcome bro @MD_Farhan1

Happy Automation!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.