# Excel remove empty rows

**URL:** <https://forum.uipath.com/t/excel-remove-empty-rows/259132>\
**Category:** Academy Feedback\
**Tags:** studio, excel, system, activities\
**Created:** [September 29, 2020, 5:47pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132 "2020-09-29T17:47:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apple1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/apple1/32/60210_2.png) [@Apple1](https://forum.uipath.com/u/Apple1)\
**Post date:** [September 29, 2020, 5:47pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/1 "2020-09-29T17:47:43Z")

</div>

Hey guys,  
Can someone advise how can I remove empty rows from excel file attached?  
[Filter\_empty.xlsx](https://forum.uipath.com/uploads/short-url/pFIJn94ZDWEdhokeftUlqvEAVHb.xlsx) (196.1 KB)  
I used Filter Data Table activity with option of Remove rows where row in field “sFound” Is Empty and after it used Write range activity to write filtered Data table back to the excel file, however not all empty rows from excle file were removed. How can I fix it?

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [September 29, 2020, 5:57pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/2 "2020-09-29T17:57:38Z")

</div>

@Apple1  
a quick look to excel did show that there are some rows where the column values have a blank  
find following alternate approach to filter out the non blank rows:  
[RemoveBlanks.xaml](https://forum.uipath.com/uploads/short-url/sWx5gc8pQHEr3ZQeTlBs4DUbnIs.xaml) (6.5 KB)

---

<div class="post-metadata">

**Author:** ![Apple1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/apple1/32/60210_2.png) [@Apple1](https://forum.uipath.com/u/Apple1)\
**Post date:** [September 29, 2020, 6:09pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/3 "2020-09-29T18:09:42Z")

</div>

@ppr  
can you explain what is done in the code:  
(From d In dtData.AsEnumerable  
Where Not If(isNothing(d(0)), True, String.IsNullOrWhiteSpace(d(0).toString.Trim))  
Select d).CopyToDataTable  
?

---

<div class="post-metadata">

**Author:** ![Apple1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/apple1/32/60210_2.png) [@Apple1](https://forum.uipath.com/u/Apple1)\
**Post date:** [September 29, 2020, 6:14pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/4 "2020-09-29T18:14:05Z")

</div>

@ppr  
can you please create and send me .xaml file using my Excel file and removing all empty rows?

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [September 29, 2020, 6:15pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/5 "2020-09-29T18:15:44Z")

</div>

@Apple1  
sure it is using LINQ

> **[Learn LINQ using Step-by-Step Tutorials](https://www.tutorialsteacher.com/linq)**
>
> Learn C# LINQ using step-by-step using practical examples. Language-Integrated Query (LINQ) is a powerful set of technologies based on the integration of query capabilities directly into the C# language.

(From d In dtData.AsEnumerable

- iterate over dtData, the datarow of current loop is referenced with d

Where Not If(isNothing(d(0)), True, String.IsNullOrWhiteSpace(d(0).toString.Trim))

- let pass the filter check if the d(0) [current loop row first column] is not null or String.Empty

Select d).CopyToDataTable

- Select the row passing the filter and copy it to a new datatable

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [September 29, 2020, 6:23pm UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/6 "2020-09-29T18:23:39Z")

</div>

> [@Apple1](#):
>
> @ppr  
> can you please create and send me .xaml file using my [Excel](https://forum.uipath.com/search?q=excel%20status%3Asolved) file and removing all empty rows?

Find starter help here:  
[RemoveBlanks\_1Col\_ExcelDemo.xaml](https://forum.uipath.com/uploads/short-url/lvkzjPHrq5aDg3vvOkDYKNe2g7g.xaml) (6.4 KB)

Adopt the Excel path as by your environment

---

<div class="post-metadata">

**Author:** ![Apple1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/apple1/32/60210_2.png) [@Apple1](https://forum.uipath.com/u/Apple1)\
**Post date:** [September 30, 2020, 4:12am UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/8 "2020-09-30T04:12:40Z")

</div>

@ppr it works thank you!  
But when I use this code with another Excel files it leaves old rows below the range where empty rows were removed, I think I need to clear excel sheet before writing new cleaned range in exsiting file, can I do it in the same code you wrote?

---

<div class="post-metadata">

**Author:** ![Apple1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/apple1/32/60210_2.png) [@Apple1](https://forum.uipath.com/u/Apple1)\
**Post date:** [September 30, 2020, 5:26am UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/9 "2020-09-30T05:26:27Z")

</div>

@ppr  
I could clean an Excel sheet with Write cell activity and everything works now.  
Can you please explain what is going on in this code step by step?  
(From d In DTFilter.AsEnumerable  
Where Not If(isNothing(d(“sFound”)), True, String.IsNullOrWhiteSpace(d(“sFound”).toString.Trim))  
Select d).CopyToDataTable

---

<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:** [October 3, 2020, 5:26am UTC](https://forum.uipath.com/t/excel-remove-empty-rows/259132/10 "2020-10-03T05:26:51Z")

</div>

Closed on October 3, 2020, 5:26am UTC

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