メインコンテンツへスキップ

Excelの複数の列から一意の値を抽出するにはどうすればよいですか?

複数の値を持つ複数の列があるとすると、いくつかの値が同じ列または異なる列で繰り返されます。 そして今、あなたはどちらかの列に一度だけ存在する値を見つけたいと思います。 Excelの複数の列から一意の値を抽出するための簡単なトリックはありますか?


数式を使用して複数の列から一意の値を抽出する

このセクションでは、365 つの数式について説明します。XNUMX つはすべての Excel バージョンに適した配列数式を使用し、もう XNUMX つは Excel XNUMX 専用の動的配列数式を使用します。

すべての Excel バージョンで配列数式を使用して複数の列から一意の値を抽出します

Excel のどのバージョンを使用しているユーザーにとっても、配列数式は、複数の列にわたって一意の値を抽出するための強力なツールとなります。その方法は次のとおりです。

1。 範囲内の値を想定 A2:C9、セルE2に次の数式を入力してください。

=INDIRECT(TEXT(MIN(IF(($A$2:$C$9<>"")*(COUNTIF($E$1:E1,$A$2:$C$9)=0),ROW($2:$9)*100+COLUMN($A:$C),7^8)),"R0C00"),)&""
Note:上記の式では、 A2:C9 一意の値を抽出するセルの範囲を示します。 E1:E1 結果を配置する列の最初のセルです。 $ 2:$ 9 行の前後に、使用するセルが含まれ、 $ A:$ C 使用するセルが列に含まれていることを示します。 自分のものに変えてください。

2。 次に、 Shift + Ctrl + Enter キーを合わせてから、塗りつぶしハンドルをドラッグして、空白のセルが表示されるまで一意の値を抽出します。 スクリーンショットを参照してください:

この式の説明:
  1. $ A $ 2:$ C $ 9:チェックするデータ範囲をA2~C9のセルで指定します。
  2. IF(($A$2:$C$9<>"")*(COUNTIF($E$1:E1,$A$2:$C$9)=0), ROW($2:$9)*100+COLUMN($A:$C), 7^8):
    • $A$2:$C$9<>"" 範囲内のセルが空でないかどうかをチェックします。
    • COUNTIF($E$1:E1,$A$2:$C$9)=0 これらのセルの値が E1 から E1 までのセル範囲にまだリストされていないかを判断します。
    • 両方の条件が満たされる場合 (つまり、値が空ではなく、列 E にまだリストされていない場合)、IF 関数は行と列に基づいて一意の数値を計算します (ROW($2:$9)*100+COLUMN($A: $C))。
    • 条件が満たされない場合、関数はプレースホルダーとして機能する大きな数値 (7^8) を返します。
  3. 分(...): 上記の IF 関数によって返された、次の一意の値の位置に対応する最小の数値を検索します。
  4. テキスト(...,"R0C00"): この最小数を R1C1 形式のアドレスに変換します。形式コード R0C00 は、数値を Excel のセル参照形式に変換することを示します。
  5. 間接(...): INDIRECT 関数を使用して、前の手順で生成された R1C1 スタイルのアドレスを通常の A1 スタイルのセル参照に変換します。 INDIRECT 関数を使用すると、テキスト文字列の内容に基づいてセルを参照できます。
  6. &「」: 式の最後に &"" を追加すると、最終出力がテキストとして扱われるため、偶数の数値もテキストとして表示されます。
 
Excel 365 の数式を使用して複数の列から一意の値を抽出する

Excel 365 は動的配列をサポートしているため、複数の列から一意の値を簡単に抽出できます。

結果を入力する空のセルに次の数式を入力またはコピーし、クリックしてください。 入力します キーを使用して、すべての一意の値を一度に取得します。スクリーンショットを参照してください:

=UNIQUE(TOCOL(A2:C9,1))


Kutools AI Aideを使用して複数の列から一意の値を抽出する

のパワーを解き放つ Kutools AI アシスタント Excel の複数の列から一意の値をシームレスに抽出します。数回クリックするだけで、このインテリジェントなツールはデータをふるいにかけ、選択した範囲全体で一意のエントリを識別してリストします。複雑な数式や VBA コードの煩わしさを忘れて、効率性を活用しましょう。 Kutools AI アシスタント Excel ワークフローをより生産的でエラーのないエクスペリエンスに変換します。

Note: 使用するには Kutools AI アシスタント of Kutools for Excelについては Kutools for Excelをダウンロードしてインストールします 最初。

Kutools for Excelをインストールした後、をクリックしてください クツールAI > AI補佐官 を開く Kutools AI アシスタント ペイン:

  1. チャット ボックスに要件を入力し、クリックします。 送信 ボタンまたはプレス 入力します 質問を送信するためのキー。
    「空白セルを無視して、範囲 A2:C9 から一意の値を抽出し、結果を E2 から開始します。」
  2. 分析後、クリックします 実行する 実行するボタン。 Kutools AI Aide は、AI を使用してリクエストを処理し、Excel の指定されたセルに結果を直接返します。


ピボットテーブルを使用して複数の列から一意の値を抽出する

ピボットテーブルに精通している場合は、次の手順で複数の列から一意の値を簡単に抽出できます。

1。 最初に、データの左側に新しい空白の列をXNUMXつ挿入してください。この例では、元のデータの横に列Aを挿入します。

2。 データ内のXNUMXつのセルをクリックして、を押します Alt + D キーを押してから、 P すぐにキーを押して開きます ピボットテーブルとピボットグラフウィザード、選択する 複数の統合範囲 ウィザードのステップ1で、スクリーンショットを参照してください。

3。 次に、をクリックします Next ボタン、チェック 私のために単一ページのフィールドを作成する ウィザードstep2のオプション。スクリーンショットを参照してください。

4。 クリックしてください Next ボタンをクリックして、セルの左側の新しい列を含むデータ範囲を選択し、をクリックします。 Add データ範囲をに追加するボタン すべての範囲 リストボックス、スクリーンショットを参照:

5。 データ範囲を選択した後、クリックを続けます Next、ウィザードの手順3で、ピボットテーブルレポートを配置する場所を好きなように選択します。

6. 最後に、 終了 ウィザードを完了し、現在のワークシートにピボットテーブルが作成されている場合は、からすべてのフィールドのチェックを外します。 レポートに追加するフィールドを選択します セクション、スクリーンショットを参照してください:

7. 次に、フィールドを確認します または値をにドラッグします ラベル、これで次のように複数の列から一意の値を取得します。


VBAコードを使用して複数の列から一意の値を抽出する

次のVBAコードを使用して、複数の列から一意の値を抽出することもできます。

1。 を押し続けます Alt + F11 キー、そしてそれは開きます Microsoft Visual Basic forApplicationsウィンドウ.

2に設定します。 OK をクリックします。 インセット > モジュール、モジュールウィンドウに次のコードを貼り付けます。

VBA:複数の列から一意の値を抽出します

Sub Uniquedata()
'Updateby Extendoffice
Dim rng As Range
Dim InputRng As Range, OutRng As Range
Set dt = CreateObject("Scripting.Dictionary")
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
For Each rng In InputRng
    If rng.Value <> "" Then
        dt(rng.Value) = ""
    End If
Next
OutRng.Range("A1").Resize(dt.Count) = Application.WorksheetFunction.Transpose(dt.Keys)
End Sub

3。 次に、 F5 このコードを実行すると、使用するデータ範囲を選択するように促すプロンプトボックスが表示されます。 スクリーンショットを参照してください:

4。 そして、 OK、結果を配置する場所を選択するための別のプロンプトボックスが表示されます。スクリーンショットを参照してください。

5. OK このダイアログを閉じると、すべての一意の値が一度に抽出されます。


より相対的な記事:

  • リストから一意で異なる値の数を数える
  • 重複するアイテムを含む値の長いリストがあるとします。次に、一意の値(リストに1回だけ表示される値)または個別の値(リスト内のすべての異なる値、つまり一意を意味する)の数をカウントします左のスクリーンショットが示すように、列内の値+ XNUMX番目の重複値)。 この記事では、Excelでこのジョブを処理する方法について説明します。
  • Excelの基準に基づいて一意の値を抽出する
  • 次のスクリーンショットのような結果を得るために、列Aの特定の基準に基づいて列Bの一意の名前のみを一覧表示する次のデータ範囲があるとします。 Excelでこのタスクをすばやく簡単に処理するにはどうすればよいですか?
  • Excelで一意の値のみを許可する
  • ワークシートの列に入力する一意の値のみを保持し、重複を防ぎたい場合、この記事では、このタスクを処理するための簡単なトリックをいくつか紹介します。
  • Excelの基準に基づいて一意の値を合計する
  • たとえば、次のスクリーンショットに示すように、[名前]列に基づいて[注文]列の一意の値のみを合計するために、[名前]列と[注文]列を含むデータの範囲があります。 このタスクをExcelですばやく簡単に解決するにはどうすればよいですか?

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (31)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Thank you for this solution, however what if the columns are in separate excel sheet? or is in separate columns instead of a table?
This comment was minimized by the moderator on the site
Hello, Jon,
The methods in this article ar only works well for a range of data, if your data in separate columns, you should copy and paste them into one range first, and then apply the formula or VBA code.
Thank you!
This comment was minimized by the moderator on the site
Thank you for this great article.

For people who are using the array formular in non-English Excel there must be taken special care of the text format string: in your example: "R0C00".
For German this would translate to "Z0S00". However, "S" is a special character refering to seconds for time formating. This character needs to be escaped and therefore the correct format string for German Excel is "Z0\S00".

I hope this helps someone in the future :-)
This comment was minimized by the moderator on the site
Hello, Michael H.
Thanks for your kindly explanation.
Hope this can help others in the future.😄
This comment was minimized by the moderator on the site
Thank you for this great article.

For people who are using the array formular in non-English Excel there must be taken special care of the text format string: in your example: "R0C00".
For German this would translate to "Z0S00". However, "S" is a special character refering to seconds for time formating. This character needs to be escaped and therefore the correct format string for German Excel is "Z0\S00".

I hope this helps someone in the future :-)
This comment was minimized by the moderator on the site
Hello Sir! The VBA worked wonders, thank you very much for that! I was wondering, If I change the original data, is it possible to refresh the column with the unique values automatically?
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hello Ioannis,

Glad to help. After you change the original data, the VBA can not refresh the result automatically. And the easiest way I can think of is to press Ctrl + Alt + F9 to refresh all results in worksheets in all open workbooks. Have a nice day.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
The array formula at the top is working great when used with data in the same sheet, however when I try to use it to reference the same exact data from another sheet the formula returns nothing. I'm unable to figure out why. Is there a limitation with array functions that prevents you from referencing ranges in a different sheet?

Thanks for any insight you can provide.
This comment was minimized by the moderator on the site
Hello Erin,

Glad to help. The INDIRECT function in this formula is more complicated to use when referencing data in other worksheets. It is not recommended to use this feature when referencing ranges in different worksheets.

For example: Now the data is in Sheet1, I want to reference the content of cell C2 of Sheet1 in Sheet2. First, in any two cells in Sheet2, such as D1 and D2, enter Sheet1 and C2, respectively. At this point, enter the formula in the empty cell of Sheet2:
=INDIRECT("'"&D1&"'!"&D2), then the content of cell C2 in Sheet1 can be returned.

As you can see, it make things way more complex. Hope my explanation can help. Have a nice day.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
Czy to żart?
This comment was minimized by the moderator on the site
can we create uniqdata function instead of macro?
This comment was minimized by the moderator on the site
Hi, İlhan,If you like a User Defined Function to create a formula for solving this problem, the below code may help you:After inserting the code, select a list of cells where you want to put the results. Then type this formula:=Uniques(A1:C4)  in the formula bar.Press Ctrl+Shift+Enter keys together. 


Function Uniques(ByVal inputRange As Range)
Dim inputArray As Variant
Dim myColl As New Collection
Dim xVal As Variant
Dim outArray() As Variant
On Error Resume Next
With inputRange
inputArray = Application.Intersect(.Cells, .Parent.UsedRange).Value
End With
On Error GoTo 0
On Error Resume Next
For Each xVal In inputArray
myColl.*** Item:=xVal, Key:=(CStr(xVal) & TypeName(xVal))
Next xVal
myColl.Remove "String"
On Error GoTo 0
ReDim outArray(1 To Application.Max(myColl.Count, Application.Caller.Cells.Count))
For xVal = 1 To UBound(outArray)
outArray(xVal) = vbNullString
Next xVal
For xVal = 1 To Application.Min(myColl.Count, Application.Caller.Cells.Count)
outArray(xVal) = myColl(xVal)
Next xVal
If Application.Caller.Columns.Count = 1 Then
Uniques = Application.Transpose(outArray)
Else
Uniques = outArray
End If
End Function
This comment was minimized by the moderator on the site
Thanks for the code. I'm using the VBA code of this page. Is there a way to add a sorting code after the unique values are extracted so it sorts it automatically?
This comment was minimized by the moderator on the site
Regarding the formula version, could you explain in more detail what this portion is doing? *100+COLUMN($A:$C),7^8)),"R0C00") Specifically, what are the *100, 7^8, and "R0C000" doing? I'm understanding everything else, but I can't figure out what these are for.
This comment was minimized by the moderator on the site
Little late for my response here but...
ROW($2:$9)*100 - this is multiplying the row number *100, so if it's in row 5, now the number is 500
COLUMN($A:$C) - this gets added to the row*100 number, so if it's row 5 col 2, then the number is 502.
7^8)), - this (I think) is to have a max value for the min statement from earlier.
"R0C00") - this formats the text based on the number. In the example, we had 502 so this gives R5C02 (row 5, col 02).

If you have a lot of columns but not many rows, then you could change it to ROW($2:$9)*1000+COLUMN($A:$C),7^8)),"R0C000")
This comment was minimized by the moderator on the site
i've adjusted to my sheet but am only returning the first value in the defined array... what am i missing?
This comment was minimized by the moderator on the site
Hello, Cody,
The above formula works well in my worksheet, could you give a screenshot of your data problem here?
Thank you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations