# Delete empty rows in excel

**URL:** <https://forum.uipath.com/t/delete-empty-rows-in-excel/487457>\
**Category:** Studio\
**Tags:** question, output-panel, studio\
**Created:** [November 5, 2022, 7:28am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457 "2022-11-05T07:28:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aregala\_Yedukondalu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aregala_yedukondalu/32/264049_2.png) [@Aregala\_Yedukondalu](https://forum.uipath.com/u/Aregala_Yedukondalu)\
**Post date:** [November 5, 2022, 7:28am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/1 "2022-11-05T07:28:09Z")

</div>

My data was coming from database and writing in the excel with empty rows, i need to delete empty rows in excel. Why because i cant move to next process with being this empty rows.  
1.Bulk data is there with empty rows need to delete empty rows.  
2.after removing if i open excel sheet need to see with out empty rows. Then only i can proceed my further process…  
Please help guys…  
Thank you

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [November 5, 2022, 7:31am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/2 "2022-11-05T07:31:16Z")

</div>

Can you share the sample input excel file with the empty rows @Aregala_Yedukondalu

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [November 5, 2022, 7:33am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/3 "2022-11-05T07:33:17Z")

</div>

Hi @Aregala_Yedukondalu ,

Could you try with the below Expression :

```auto
DT = DT.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or String.IsNullOrWhitespace(field))).CopyToDataTable()

```

Here, `DT` is the datatable retrieved from Database.

To Handle errors with Direct CopyToDatatable, Check the below post :

> [@ambulance sos \[FirstAid\] Handling of The source contains no DataRows exception](https://forum.uipath.com/t/firstaid-handling-of-the-source-contains-no-datarows-exception/410526):
>
> This FirstAid Tutorial will describe how a the source contains no DataRows EXCEPTION can be handled. Introduction Let’s have a look at the following filter data table scenario: Name CCode Tom US Charlotte FR Seema IN Jean FR Assignment: Filter all rows on a particular Country Code like FR, UK, ES, UK… Ensure that all CCode data column values are trimmed Ensure that the Filter check is case insensitive we can implement it e.g. with the help of a LINQ statement: dtData.AsE…

---

<div class="post-metadata">

**Author:** ![Aregala\_Yedukondalu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aregala_yedukondalu/32/264049_2.png) [@Aregala\_Yedukondalu](https://forum.uipath.com/u/Aregala_Yedukondalu)\
**Post date:** [November 5, 2022, 7:36am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/4 "2022-11-05T07:36:01Z")

</div>

Thanks  
But i am using C# Can u help in this…

---

<div class="post-metadata">

**Author:** ![Aregala\_Yedukondalu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aregala_yedukondalu/32/264049_2.png) [@Aregala\_Yedukondalu](https://forum.uipath.com/u/Aregala_Yedukondalu)\
**Post date:** [November 5, 2022, 7:36am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/5 "2022-11-05T07:36:46Z")

</div>

Sure… Here is the sample file  
[Book2.xlsx](https://forum.uipath.com/uploads/short-url/djAs7M903AuD7HoymlbECTgr9gx.xlsx) (9.0 KB)

---

<div class="post-metadata">

**Author:** ![Tapan\_Behera1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/tapan_behera1/32/497450_2.png) [@Tapan\_Behera1](https://forum.uipath.com/u/Tapan_Behera1)\
**Post date:** [November 5, 2022, 7:38am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/6 "2022-11-05T07:38:17Z")

</div>

Hi @Aregala_Yedukondalu you can also use the filter data table activity to remove the empty rows.

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [November 5, 2022, 7:44am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/7 "2022-11-05T07:44:39Z")

</div>

> [@Aregala\_Yedukondalu](#):
>
> But i am using C# Can u help in this…

@Aregala_Yedukondalu ,

Could you Check with the updated Expression below :

```auto
DT.Rows.Cast<DataRow>().Where(row=>!(row.ItemArray.All(field=>field == null | String.IsNullOrEmpty(field.ToString())))).CopyToDataTable()

```

---

<div class="post-metadata">

**Author:** ![Gokul\_Jayakumar](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul_jayakumar/32/425938_2.png) [@Gokul\_Jayakumar](https://forum.uipath.com/u/Gokul_Jayakumar)\
**Post date:** [November 5, 2022, 7:50am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/8 "2022-11-05T07:50:12Z")

</div>

> [@Aregala\_Yedukondalu](#):
>
> , i need to delete empty rows in excel.

Hello @Aregala_Yedukondalu  
You can use the Filter Data table, While data get from the database is stored in a Data Table variable.  
Filter the data table using the not empty conditions and save it in a another Data table variable and write into excel sheet.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/3/4/1/341f739f2efbce0fb9b3d36f6a3a00760b223670.png)

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [November 5, 2022, 8:03am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/10 "2022-11-05T08:03:54Z")

</div>

@Aregala_Yedukondalu ,

Could you try writing the Datatable to a different Sheet ? Sheet2 ?

Check if the data in Sheet2 is appearing properly, we could then decide if you want to modify the Sheet1 data itself or if you could consider the Sheet2 as the Output sheet.

---

<div class="post-metadata">

**Author:** ![Aregala\_Yedukondalu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aregala_yedukondalu/32/264049_2.png) [@Aregala\_Yedukondalu](https://forum.uipath.com/u/Aregala_Yedukondalu)\
**Post date:** [November 5, 2022, 9:29am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/11 "2022-11-05T09:29:31Z")

</div>

In sheet2 data appearing properly but i need in sheet 1 only  
Thanks…

---

<div class="post-metadata">

**Author:** ![supermanPunch](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/supermanpunch/32/133652_2.png) [@supermanPunch](https://forum.uipath.com/u/supermanPunch)\
**Post date:** [November 5, 2022, 9:48am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/12 "2022-11-05T09:48:37Z")

</div>

> [@Aregala\_Yedukondalu](#):
>
> but i need in sheet 1 only

@Aregala_Yedukondalu ,

If that is the case, then we can perform a Clear Data operation using `Write Cell` Activity first on the Sheet, then you can use `Write Range` Activity on the Same sheet.

If you have access to Modern Excel Activities, then you could try with the below Approach as well using `Clear Sheet/Range/Table` Activity.  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/b/c/0/bc09ac56a37fa7cab3896dd89ed8483736b7b6ea.png)

If modern activities are not preferred, then you could check with the below post on using `Write Cell` Activity to Clear the Sheet.

> [@Delete Excel data range without Excel Installed](https://forum.uipath.com/t/topic/411683/5):
>
> @kasey.betts , Assuming that we have the Data already available in Datatable, which Represents the Data in the Excel, we can use it’s Column Count and Row Count information to Clear the Contents using Write Cell Activity. For Example : Let the Datatable be DT We get the Column Letter of the Excel by using the Column Count information as follows : columnLetter = UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(DT.Columns.Count+1) The above would help us get the Col…

---

<div class="post-metadata">

**Author:** ![Aregala\_Yedukondalu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aregala_yedukondalu/32/264049_2.png) [@Aregala\_Yedukondalu](https://forum.uipath.com/u/Aregala_Yedukondalu)\
**Post date:** [November 5, 2022, 10:27am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/13 "2022-11-05T10:27:30Z")

</div>

I posted a sample sheet in real scenario there are multiple headers and multiple sheets are there…  
Thanks…

---

<div class="post-metadata">

**Author:** ![Gokul\_Jayakumar](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul_jayakumar/32/425938_2.png) [@Gokul\_Jayakumar](https://forum.uipath.com/u/Gokul_Jayakumar)\
**Post date:** [November 5, 2022, 11:21am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/14 "2022-11-05T11:21:34Z")

</div>

@Aregala_Yedukondalu  
Find the XAML attached here, the Same concept can applicable for all sheets, read the range and pass the DT by removing the empty vales, it will remove and filter the data.  
[Forum\_FilterEmptycell.zip](https://forum.uipath.com/uploads/short-url/pM0MvRpzIRUwRH4HLauts1UIS0n.zip) (14.3 KB)

---

<div class="post-metadata">

**Author:** ![Aregala\_Yedukondalu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aregala_yedukondalu/32/264049_2.png) [@Aregala\_Yedukondalu](https://forum.uipath.com/u/Aregala_Yedukondalu)\
**Post date:** [November 5, 2022, 11:24am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/15 "2022-11-05T11:24:35Z")

</div>

Thank you so much… now its working fine @supermanPunch

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [November 8, 2022, 11:25am UTC](https://forum.uipath.com/t/delete-empty-rows-in-excel/487457/16 "2022-11-08T11:25:26Z")

</div>

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