How to remove last row in excel

how to remove last row in a particular excel and how to remove particular column rows and reflect the output in same excel file

@anjani_priya

modifiy the datatable

Remove the last row

dataTable.AsEnumerable().SkipLast(1).CopyToDataTable()

after modidfiy the datatable

Remove a particular column

modifiedDataTable.Columns.Remove(columnNameToRemove)

cheers…!

I need to remove the rows example if the column name is dept. It has some values like finance , IT, manufacturing,HR
I need to remove all the rows of HR
how to remove that

Hi @anjani_priya

You can simply use Filter DataTable activity

Cheers!!

1 Like

@anjani_priya

try this one

dataTable.AsEnumerable().Where(Function(row) row.Field(Of String)(column_Name) <> valueToRemove).CopyToDataTable()

or

You can simply use Filter DataTable activity

cheers…!

1 Like

Hi @anjani_priya

You can use the Delete row activity to delete the last row in the excel. To know the last row of a column before using delete row activity use the find first\last row activity to know the last row.
Give the output of Find first\last row activity to the input of Delete row activity.

Find first\Last row activity → Give the specified column name in the Column name field.
Create a variable in the Save last row number as field as LastRow.
Delete row → Pass the LastRow variable in the At Position field.

These two activities are modern excel activities, check the below workflow for better understanding,

Hope it helps!!

Hi @anjani_priya

You can use the below sequence using the macros

Here is the text file code for removing the last row. Use invoke VBA to execute the code in text file. Change the sheet names according to your requirement
RemoveLastRow.txt (182 Bytes)
e

Regards

the data should remove in the excel sheet which we read
if i use same sheet and i have used filter datatable then the data is writing double times

if iam using filter datatable the data is printing again
But i need to reflect the removal in the same sheet how to do it

@anjani_priya

Can you try the below sample?

Remove HR Rows.txt (917 Bytes)

Input:
image

Output:
image

Hope this helps!!

is there regular activities for this instead of vba

can you tell the solution with normal activities

Hi @anjani_priya

Hope you find solution for this question

Hi @anjani_priya

You can try this in invoke code

**

Note : - I have taken the sample row as it instead of it you can take as Hr

**

For Each r As datarow In in_dt.AsEnumerable()
	r("Date")=DateTime.ParseExact(r("Date").ToString,"MM/dd/yyyy hh:mm:ss",System.Globalization.CultureInfo.CurrentCulture).ToString("dd-MM-yyyy")
Next
in_dt=in_dt.AsEnumerable().Where(Function(x) x("dept").ToString<>"it").CopyToDataTable

can you share as a xaml file

Date&Removehr.zip (1.7 KB)

@anjani_priya

@anjani_priya
Happy Automation

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