How to delete entire row in excel if the specific column is empty

Hi everyone,

I have following for filter and delete rows (excel activity) and tick for “has header”. It works but the result has been deleted with the header. Is it because the header start from Row “A3”? Cannot use specific rows or index because the data might be huge and did not know what the index might be empty.

Do you have any solution on this? If header start from A3 and can delete the entire last row where the column is empty.

Input:

image

Expected result:

image

Thanks

1 Like

Welcome back to forum

Have a view on these threads where similar discussion happened earlier with solutions mentioned

Hope this helps

Cheers @Nur.ain

Hi @Nur.ain ,

Could you let us know what were the activities used ? Was it Workbook or Excel activities ?

With Read Range Workbook activity we get the proper datatable output when Range is kept blank.

From Implementation and Debug :

The Input Excel sheet :
image

Hi @Nur.ain

Read range workbook (originalDt)
Try this linq query in assign:


filteredDt = originalDt.AsEnumerable().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(""))).CopyToDataTable()

Write Range Excel (filteredDt)

My workflow like this. I’m using Excel activities

I try do as the as you given but the result not as expected. My header not start from A1. It start from A3.

The result should be as below screenshot:

image

I think if header start from A1:C1, yes the result as expected. Did I need to change or set anything to start from A3:C3?

I try and the result different because my header start from A3:C3

While writing with write range activity yu can mention the start range u want
There just mention the first cell from where u want to start like “A1” or “A3”

@Nur.ain

I did the cell A3:C3 the result was like did not happen anything.

Result:

image

Hi @Nur.ain

How about the following?

(From row In DT.AsEnumerable()
          Where Not String.IsNullOrEmpty(row.ItemArray(1).ToString())
          Select row).CopyToDataTable()

I/P:
image

O/P:
image

Hope this helps!!

Yup, correct! But, I want to use the same “Sheet1”. If I do write range for sheet 2 yes it did it.

Do you have any way to do in the same Sheet?

Hi @Nur.ain ,

For Writing to the Same sheet or overwrite the data existing, sometimes the data to be written is lesser than the ones present in the Excel sheet. In these cases, we would require to clear the sheet contents at first and then write the Data to the sheet.

For this one of the methods is mentioned below :

We could also create empty rows and add/append the empty rows to the Datatable according to the total rows present in the Existing sheet and then write the datatable to the same sheet. Topics related to creating empty rows :

mention the range just as “A1” then it will start from first cell and not “A3”

we dont need to mention fully like “A3:C3”
Just mention the first cell within double quotes

@Nur.ain

HI @Nur.ain

Please follow the below Steps.
Step1: use Filter data table Option
Step2: select remove in that provide the column name and and is empty.
image

Delete Empty Row.xaml (8.1 KB)

If you are dynamic cell is empty then you have to look and put the if condition and remove the rows or delete row activity and delete

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