![](https://excel-vba.work/wp-content/themes/cocoon-master/images/b-woman.png)
VBAで
・配列から重複を除く
ことができます!
※簡易にできます。
![配列](https://excel-vba.work/wp-content/uploads/2022/09/vba_unique_arr_003.png)
![重複が除かれた配列](https://excel-vba.work/wp-content/uploads/2022/09/vba_unique_arr_002.png)
![](https://excel-vba.work/wp-content/themes/cocoon-master/images/b-woman.png)
VBAから
・ワークシート関数である「UNIQUE関数」
を使用することで実現できます!
※UNIQUE関数はOffice365のExcelでのみ使用できる関数です。
VBAコード
ここでは例として、
・配列から重複を除いて
・イミディエイトウインドウへ出力
します。
Option Explicit
Sub sample()
Dim arr As Variant
Dim arrUnique As Variant
Dim item As Variant
'配列を作成
arr = Array("佐藤", "吉田", "加藤", "田中", "佐藤", "吉田", "加藤")
'配列から重複を除く
arrUnique = WorksheetFunction.Unique(arr, True)
For Each item In arrUnique
'重複が除かれた配列をイミディエイトウインドウへ出力
Debug.Print item
Next
End Sub
実行結果
配列から重複を除くことができました。
![実行結果](https://excel-vba.work/wp-content/uploads/2022/09/vba_unique_arr_002.png)
参考①
シート上のデータを取得して、「重複が除かれた配列」を作成することもできます。
詳細は以下の記事をご確認ください。
参考②
シート上のデータの重複を除くこともできます。
詳細は以下の記事をご確認ください。
参考③
上記のVBAコードで使用した以下の詳細は、公式サイトをご確認ください。
●UNIQUE関数
●イミディエイトウィンドウへ出力