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

セルの文字列内の重複する文字や単語を削除するにはどうすればよいですか?

各セルに重複する文字または単語があり、重複を削除して一意の文字または単語のみを残したいとします。 Excelでこの問題をどのように解決できますか?

ユーザー定義関数を使用してテキスト文字列の重複文字を削除する

ユーザー定義関数を使用して、句読点で区切られた重複する単語を削除します


矢印青い右バブル ユーザー定義関数を使用してテキスト文字列の重複文字を削除する

テキスト文字列のリストがある場合は、次のスクリーンショットに示すように、重複する文字を削除する必要があります。 ここでは、それに対処するためのVBAコードについて説明します。

doc-重複文字の削除-1

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

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

VBAコード:セル内のテキスト文字列の重複文字を削除します

Function RemoveDupes1(pWorkRng As Range) As String
'Updateby Extendoffice
Dim xValue As String
Dim xChar As String
Dim xOutValue As String
Set xDic = CreateObject("Scripting.Dictionary")
xValue = pWorkRng.Value
For i = 1 To VBA.Len(xValue)
    xChar = VBA.Mid(xValue, i, 1)
    If xDic.Exists(xChar) Then
    Else
        xDic(xChar) = ""
        xOutValue = xOutValue & xChar
    End If
Next
RemoveDupes1 = xOutValue
End Function

3。 次に、このコードを保存して閉じ、ワークシートに戻って、この数式を入力します = removedupes1(A2) (A2 重複を削除するデータセルは、データ以外の空白のセルになります。スクリーンショットを参照してください。

doc-重複文字の削除-1

4。 次に、この数式を適用する範囲セルに塗りつぶしハンドルをドラッグすると、重複するすべての文字が各セルからすぐに削除されます。

doc-重複文字の削除-1


矢印青い右バブル ユーザー定義関数を使用して、句読点で区切られた重複する単語を削除します

セル内に特定の句読点で区切られた単語がある場合は、必要に応じて重複する単語を削除することもできます。 次の手順で実行してください。

1. 押したまま Alt + F11 キーを押して Microsoft Visual Basic forApplicationsウィンドウ.

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

VBAコード:セルの句読点で区切られた重複する単語を削除します

Function RemoveDupes2(txt As String, Optional delim As String = " ") As String
    Dim x
    'Updateby Extendoffice
    With CreateObject("Scripting.Dictionary")
        .CompareMode = vbTextCompare
        For Each x In Split(txt, delim)
            If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing
        Next
        If .Count > 0 Then RemoveDupes2 = Join(.keys, delim)
    End With
End Function

3。 次に、このコードを保存して閉じ、ワークシートに戻って、この数式を入力します = RemoveDupes2(A2、 "、") データの横の空白のセルに、スクリーンショットを参照してください。

doc-重複文字の削除-1

4。 次に、数式を必要なセルにコピーすると、重複する単語がすべてすべてのセルから削除されます。 スクリーンショットを参照してください:

doc-重複文字の削除-1

Note:上記の式では、 A2 使用するセルを示し、コンマ(、)はセル内の単語を区切る句読点を表します。必要に応じて、他の句読点に変更できます。

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

🤖 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 (67)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
How to remove duplicate words in excel template


Flooring|Tiles Flooring|Flooring|Vitrified Tiles|Tiles|Flooring|Tiles
This comment was minimized by the moderator on the site
Not sure if this thread is still alive. I am trying to use this for something as simple as what is shown in the chart above and I keep on receiving #NAME? error. Cell A2 has XXX, YYY, XXX, AAA I can't quite understand what I am doing wrong. I have the code in my personal workbook. Would that be the issue?
This comment was minimized by the moderator on the site
Thank you for the beautiful and useful coding. Can we do the same using Power Query?
This comment was minimized by the moderator on the site
Hi, is there a way to get the result of "RemoveDupes2" alphabetically sorted?
This comment was minimized by the moderator on the site
Hey! can anyone help me,
I have a data in excel example:



CARITAS, CSCED, FREE, NRC
BOSADP, DHCBI
BOSADP, Mercy Corps, NRC
ADRA, NRC
BOSADP, CAID
AAH, FAO (NEYIF), CRS (NEYIF)
SWNI, Mercy Corps,
CARE, PLAN, NRC
Mercy Corps, NRC
BOSADP, DHCBI, GREENCODE, NRC, AAH BOSADP


What I really want

CARITAS
BOSADP
DHCBI
NRC
ADRA
CAID
AAH
FAO
NEYIF
CRS
SWNI
CARE
PLAN
Mercy Corps
GREENCODE
FREE


the repeated words separated by comma deleted and and those that not repeated but separated by comma move to the next columns
This comment was minimized by the moderator on the site
Hey! can anyone help me,
I have a data in excel example:



CARITAS, CSCED, FREE, NRC
BOSADP, DHCBI
BOSADP, Mercy Corps, NRC
ADRA, NRC
BOSADP, CAID
AAH, FAO (NEYIF), CRS (NEYIF)
SWNI, Mercy Corps,
CARE, PLAN, NRC
Mercy Corps, NRC
BOSADP, DHCBI, GREENCODE, NRC, AAH BOSADP


What I really want

CARITAS
BOSADP
DHCBI
NRC
ADRA
CAID
AAH
FAO
NEYIF
CRS
SWNI
CARE
PLAN
Mercy Corps
GREENCODE
FREE


the repeated words separated by comma deleted and and those that not repeated but separated by comma move to the next columns
This comment was minimized by the moderator on the site
i tried applying method2 to numbers but it does not work. eg. 1104, 1104, 203, 203, 409, 409 >>>1104, 203, 409 How do you get method 2 to work with numbers?
This comment was minimized by the moderator on the site
Hello, deezy,
The second method works well for numbers, please see the below screenshot.
Please try it again, thank you!
This comment was minimized by the moderator on the site
Thanks so much for sharing knowledge, I used the "Remove Duplicate Words Separated By Punctuation With User Defined Function" and it worked great. May you knowledge grow and grow.
This comment was minimized by the moderator on the site
how about to remove duplicate character with an exception

for example from MMMPXLL, i want to remove M but keep the L

so the result will be MPXLL
This comment was minimized by the moderator on the site
Edit :

some problem solved with removedupes2, but i have to do it one by one

for example i cant remove duplicate letter y,a,l at once. I have to do it one by one.

also, for case there is data like this yyypl, it become pl, the "y" is totally removed
This comment was minimized by the moderator on the site
i have a string of text like so

1 Ser 1 Ser 1 Ser 1 Ser 1 Ser 1 Ser 1 Ser 1 Ser 1 Ser 2 Ser 2 Ser 2 Ser 2 Ser 2 Ser 2 Ser 2 Ser 2 Ser 3 Ser 3 Ser 3 Ser 3 Ser 3 Ser 3 Ser 3 Ser 3 Ser X3 X5

when applying remove dupes 2 i get

1 Ser 2 3 X3 X5


by the looks of it, all duplicates except the first instance are kept, is there any way to tweek this so all duplicate instances except the last occurance are kept ?

so my desired outcome would be

1 2 3 Ser X3 X5

thank you in advanced!
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