跳至主要内容

如何在 Excel 中将重复的行移动到另一个工作表?

Author: Xiaoyang Last Modified: 2025-05-07

如果你有一个包含特定列中某些重复值的数据区域列表,现在,你想根据重复的单元格将整行移动到另一个工作表。你如何在 Excel 中处理这个任务呢?

根据列中的重复单元格将整行移动到另一个工作表

根据重复行将整行移动到另一个工作表


根据列中的重复单元格将整行移动到另一个工作表

如果某一列中有重复值,则将整行移动到另一个工作表,以下 VBA 代码可以帮到你:

1. 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

2. 单击 插入 > 模块,并将以下代码粘贴到模块窗口中。

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 键运行此代码,在弹出的对话框中,选择包含要移动的重复单元格的列,请参见截图:

select the column which contains the duplicate cells to move based on

4. 然后单击“确定”,在另一个提示框中,请选择另一个工作表中要放置移动行的单元格,请参见截图:

elect a cell in another sheet to put the moved rows

5. 然后单击“确定”,A 列中具有重复值的行已被移动到新工作表中,请参见截图:

the rows which have duplicate values in column A are moved into a new sheet

a screenshot of kutools for excel ai

使用 Kutools AI 解锁 Excel 魔法

  • 智能执行:执行单元格操作、分析数据和创建图表——所有这些都由简单命令驱动。
  • 自定义公式:生成量身定制的公式,优化您的工作流程。
  • VBA 编码:轻松编写和实现 VBA 代码。
  • 公式解释:轻松理解复杂公式。
  • 文本翻译:打破电子表格中的语言障碍。
通过人工智能驱动的工具增强您的 Excel 能力。立即下载,体验前所未有的高效!

根据重复行将整行移动到另一个工作表

如果你想从一系列单元格中移动重复的行,以下 VBA 代码可以帮助你:

1. 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

2. 单击 插入 > 模块,并将以下代码粘贴到模块窗口中。

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 键运行此代码,在弹出的对话框中,选择要移动重复行的数据区域,请参见截图:

select the select the data range to move the duplicate rows

4. 单击“确定”按钮,然后在另一个提示框中,选择新工作表中要放置移动重复行的单元格,请参见截图:

select a cell in a new sheet to put the moved supplicate rows

5. 然后单击“ 确定”按钮,现在,重复的行已一次性移动到你指定的另一个工作表中,请参见截图:

the duplicate rows are moved into another sheet

最佳办公效率工具

🤖 Kutools AI 助手:基于智能执行生成代码创建自定义公式分析数据并生成图表调用 Kutools 函数等功能,彻底改变数据分析方式…
热门功能查找、高亮或标记重复项 | 删除空行 | 合并不丢失数据的列或单元格 | 四舍五入 ...
高级 LOOKUP多条件 VLookup | 多值 VLookup | 多表查找 | 模糊查找 ....
高级下拉列表快速创建下拉列表 | 从属下拉列表 | 多选下拉列表 ....
列管理器添加指定数量的列 | 移动列 | 切换隐藏列的可见状态 | 比较区域和列 ...
精选功能网格聚焦 | 设计视图 | 增强编辑栏 | 工作簿与工作表管理器 | 资源库(自动文本) | 日期提取 | 合并数据 | 加密/解密单元格 | 按列表发送电子邮件 | 超级筛选 | 特殊筛选(筛选粗体/斜体/删除线...)...
排名前 15 的工具集12 种文本 工具添加文本删除特定字符等) | 50 多 种图表 类型甘特图等) | 40 多种实用 公式基于生日计算年龄等) | 19 种插入 工具插入二维码根据路径插入图片等) | 12 种转换 工具小写金额转大写汇率转换等) | 7 种合并与分割 工具高级合并行分割单元格等) | 还有更多...

使用 Kutools for Excel 提升您的 Excel 技能,体验前所未有的高效。 Kutools for Excel 提供超过 300 种高级功能来提高生产力并节省时间。 单击此处获取您最需要的功能...


Office Tab 将标签式界面引入 Office,让您的工作更加轻松

  • 在 Word、Excel、PowerPoint 中启用标签式编辑和阅读
  • 在同一窗口的新标签页中打开和创建多个文档,而不是在新窗口中进行操作。
  • 将您的生产力提升 50%,每天为您减少数百次鼠标点击!