# エクセルの重複を除いてデータを一つ一つ取り出す方法

**URL:** <https://forum.uipath.com/t/topic/55617>\
**Category:** アカデミー\
**Tags:** excel\
**Created:** [August 6, 2018, 12:29am UTC](https://forum.uipath.com/t/topic/55617 "2018-08-06T00:29:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![361oosugi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/361oosugi/32/181989_2.png) [@361oosugi](https://forum.uipath.com/u/361oosugi)\
**Post date:** [August 6, 2018, 12:29am UTC](https://forum.uipath.com/t/topic/55617/1 "2018-08-06T00:29:41Z")

</div>

例えば、エクセルの列から重複したデータを取り除いた状態で、存在する項目だけを打ち出す方法はありますでしょうか？以下の場合、りんご、みかん、ぶどうだけをそれぞれ、String型の変数に入れる方法を知りたいのですが、お分かりになりますでしょうか？Remove Duplicate Rowsはバージョンが古いため、使用できません。#NET関数を使用する方法でも大丈夫です。  
B列  
りんご  
りんご  
みかん  
みかん  
みかん  
ぶどう  
ぶどう

---

<div class="post-metadata">

**Author:** ![ak\_mariam](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@ak\_mariam](https://forum.uipath.com/u/ak_mariam)\
**Post date:** [August 6, 2018, 3:52am UTC](https://forum.uipath.com/t/topic/55617/2 "2018-08-06T03:52:05Z")

</div>

Excelから抜き出したB列をDatatableに格納し、For each rowで回しながらListに追加するのはいかがでしょうか。  
For each row内部のIFブロックにて、すでにListにある場合は追加しない、という判断を入れればよいかと思います。（Listにない場合はlst.IndexOf(row(0).ToString) の結果が-1になります）

Assign  
lst = new List(of String)

For each row in dt  
If lst.IndexOf(row(0).ToString) = -1  
then Add to collection  
Collection：lst  
Item：row(0).ToString

---

<div class="post-metadata">

**Author:** ![361oosugi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/361oosugi/32/181989_2.png) [@361oosugi](https://forum.uipath.com/u/361oosugi)\
**Post date:** [August 6, 2018, 4:48am UTC](https://forum.uipath.com/t/topic/55617/3 "2018-08-06T04:48:30Z")

</div>

@ak_mariam 様

具体的なWFの事例 (xamlファイル) をご教示頂けますと幸いです。

---

<div class="post-metadata">

**Author:** ![galbeath123](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@galbeath123](https://forum.uipath.com/u/galbeath123)\
**Post date:** [August 6, 2018, 5:37am UTC](https://forum.uipath.com/t/topic/55617/4 "2018-08-06T05:37:54Z")

</div>

@361oosugiさん  
どこまで作られたのでしょうか？何を試してダメだったのでしょうか。  
最終的にやりたいことが何なのかずれていることがよくあるので、  
確認するために、作ったところまでをアップしてみてください。  
もしかするとstringに入れる、ではなく、もっと適した方法があったりするかもしれませんよ。

ちなみに、DefaultView.ToTableとするとユニークな情報を取得できます。  
たとえばdataTable1(例)にExcelを取り込んだあと、  
dataTable1.DefaultView.ToTable(true, “B列のタイトル”)  
とするとdistinctな状態になったDataTableが戻ってきます。

あとはfor each rowで取ってきた値をlistに入れるなり、なんなりすればOKかと。

類似の情報がありますので検索してください。

> [@How to create second excel sheet with only unique entries from first excel sheet](https://forum.uipath.com/t/how-to-create-second-excel-sheet-with-only-unique-entries-from-first-excel-sheet/34430):
>
> Hi, I have an excel sheet that I want to duplicate but only enter unique entries from the first sheet. I am at a loss as to how to go about this. I’ve tried nested “for each row’s”, and looked at some of the more complicated answers for manipulating data tables, but that’s more advanced than I know how to understand. Any help would be appreciated, Thanks,
