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

重複する行をExcelの別のシートに移動するにはどうすればよいですか?

特定の列に重複する値を含むデータ範囲のリストがある場合は、重複するセルに基づいて行全体を別のシートに移動します。 Excelでこのタスクをどのように処理できますか?

列内の重複セルに基づいて、行全体を別のシートに移動します

重複する行に基づいて、行全体を別のシートに移動します


列内の重複セルに基づいて、行全体を別のシートに移動します

列に重複する値がある場合は、行全体を別のシートに移動します。次のVBAコードを使用すると便利です。

1。 を押し続けます Alt + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

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

VBAコード:列内の重複セルに基づいて、行全体を別のシートに移動します。

Sub CutDuplicates()
'Updateby Extendoffice
    Dim xRgS As Range
    Dim xRgD As Range
    Dim I As Long, J As Long
    On Error Resume Next
    Set xRgS = Application.InputBox("Please select the column:", "KuTools For Excel", Selection.Address, , , , , 8)
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Application.InputBox("Please select a desitination cell:", "KuTools For Excel", , , , , , 8)
    If xRgD Is Nothing Then Exit Sub
    xRows = xRgS.Rows.Count
    J = 0
    For I = xRows To 1 Step -1
        If Application.WorksheetFunction.CountIf(xRgS, xRgS(I)) > 1 Then
            xRgS(I).EntireRow.Copy xRgD.Offset(J, 0)
            xRgS(I).EntireRow.Delete
            J = J + 1
        End If
    Next
End Sub

3。 次に、 F5 このコードを実行するにはキーを押し、ポップアウトされたダイアログボックスで、移動先の重複セルを含む列を選択します。スクリーンショットを参照してください。

4。 次に、をクリックします OK、別のプロンプトボックスで、移動した行を配置する別のシートのセルを選択してください。スクリーンショットを参照してください。

5。 そして、 OK、列Aの値が重複している行は、新しいシートに移動されました。スクリーンショットを参照してください。


重複する行に基づいて、行全体を別のシートに移動します

セルの範囲から重複する行を移動する場合は、次のVBAコードが役立ちます。

1。 を押し続けます Alt + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

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

VBAコード:重複する行に基づいて、行全体を別のシートに移動します。

Sub CutDuplicates()
'Updateby Extendoffice
    Dim xRgD As Range, xRgS As Range
    Dim I As Long, J As Long, K As Long, KK As Long
    On Error Resume Next
    Set xRgS = Application.InputBox("Please select the data range:", "KuTools For Excel", Selection.Address, , , , , 8)
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Application.InputBox("Please select a desitination cell:", "KuTools For Excel", , , , , , 8)
    If xRgD Is Nothing Then Exit Sub
    KK = 0
    For I = xRgS.Rows.Count To 1 Step -1
        For J = 1 To I - 1
            For K = 1 To xRgS.Columns.Count
                Debug.Print xRgS.Rows(I).Cells(, K).Value
                Debug.Print xRgS.Rows(J).Cells(, K).Value
                If xRgS.Rows(I).Cells(, K).Value <> xRgS.Rows(J).Cells(, K).Value Then Exit For
            Next
            If K = xRgS.Columns.Count + 1 Then
                xRgS.Rows(I).EntireRow.Copy xRgD.Offset(KK, 0).EntireRow
                xRgS.Rows(I).EntireRow.Delete
                KK = KK + 1
            End If
        Next
    Next
End Sub

3。 次に、 F5 このコードを実行するためのキーを押して、ポップアウトされたダイアログボックスで、重複する行を移動するデータ範囲を選択します。スクリーンショットを参照してください。

4に設定します。 OK をクリックします。 OK ボタンをクリックし、別のプロンプトボックスで、移動した嘆願の行を配置する新しいシートのセルを選択します。スクリーンショットを参照してください。

5。 次に、をクリックします OK ボタンをクリックすると、重複した行が一度に指定した別のシートに移動されました。スクリーンショットを参照してください。

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

🤖 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 (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hola buenas,

Tenia una pregunta con respecto a esta macro; Esta macro es exactamente lo que necesito y funciona perfectamente, pero mi problema es que solo funciona en grupo de datos que no sean muy grandes.

Cuando la aplico sobre un grupo de datos grandes (en mi caso, 50mil filas), excel inevitablemente colapsa; He probado muchas cosas pero sigue colapsando.

Hay alguna manera de hacer que la macro funcione en estos casos? alguna idea? Gracias de antemano.

Rafael.
This comment was minimized by the moderator on the site
Hello, Rafael

Yes, as you said, if the data is large, the vba code will not work perfectly. In this case, you can use the auxiliary column to mark the duplicate row first, then use the filter function to filter out the duplicate row, finally copy the duplicate row to another worksheet. Please see the below demo:
To find the duplicate rows, please apply this formula: =IF(COUNTIFS($A$2:$A2,$A2,$B$2:$B2,$B2,$C$2:$C2,$C2) >1, "Duplicate row", "")
If you just want to find the duplicate cells in one column, please apply this formula: =IF(COUNTIFS($A$2:$A2,$A2) >1, "Duplicate row", "")
https://www.extendoffice.com/images/stories/comments/comment-skyyang/move-duplicates.gif
Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hola, que tal,

Tengo una duda con respecto a esta macro; La macro funciona perfectamente y es justo lo que necesito, el problema es que habitualmente necesito utilizarla con tablas de excel en las que hay como mas de 50 mil entradas.

Al utilizarla, Excel inevitablemente se colapsa y no responde.

Hay alguna manera de conseguir que esta macro funcione en estos casos? O quizas, conseguir alguna formula/combinacion de formulas en excel que haga lo mismo? Lo comento porque en el caso de las formulas, normalmente excel no suele tardar tanto en procesar y lo resuelve mas rapido.

Un saludo, y gracias.

Rafael.
This comment was minimized by the moderator on the site
For some reason. This worked once, but I cant run it again. IT keeps timing out. Any tips?
This comment was minimized by the moderator on the site
It's working bro!!!!! Thanks.
This comment was minimized by the moderator on the site
This is exactly what I was looking for, thank you! I did it wrong the first few times and then it kept freezing. But once I did it exactly like the screenshots (selecting the exact range, copy/pasting the headers in the other sheet, and only selecting the first field under the first header) the macros was instantaneous.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations