跳到主要内容

如何删除重复项,但保留Excel中其余的行值?

在Excel中,当您应用“删除重复项”功能时,它将删除所有重复值并向上移动,如屏幕截图1所示。 但是,在某些情况下,您可能希望删除重复项,但保留其余的行值,如屏幕截图2所示。 现在,在这种情况下,我将介绍一些删除重复项但将其余部分保留在Excel中的技巧。

doc删除重复项以保持休息1 doc删除重复项以保持休息2

删除重复项,但使用过滤器保留其余的行值(3个步骤)

删除重复项,但使用VBA保留其余的行值(4个步骤)

使用 Kutools for Excel 删除重复项但保留其余行值(2步)好主意3


删除重复项,但使用过滤器保留其余行值

使用公式和过滤器功能,您可以快速删除重复项,但要保持休息。

1.在数据范围(例如,D2)旁边选择一个空白单元格,键入公式 = A3 = A2,将自动填充手柄向下拖动到所需的单元格。 看截图:
doc删除重复项以保持休息3

2.选择所有数据范围,包括公式单元格,然后单击 时间 > 筛选器 启用 筛选器 功能。 看截图:
doc删除重复项以保持休息4

3。 点击 筛选器图标 在D列(公式列)中,然后检查 TUR从下拉列表E中查看屏幕截图:
doc删除重复项以保持休息5

4。 点击 OK,然后列出所有重复项,然后选择所有重复值,按 删除 删除它们的关键。 看截图:
doc删除重复项以保持休息6

5。 点击 时间 > 筛选器 禁用 筛选器,然后根据需要删除公式。 您可以看到所有重复项均已删除,其余值保留在该行中。
doc删除重复项以保持休息7


删除重复项,但使用VBA保留其余的行值

在Excel中,有一个VBA代码,该代码也可以删除重复项,但保留其余的行值。

1。 按 Alt + F11键 显示键 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > e,然后将以下代码粘贴到 模块.

VBA:删除重复项,但保留其余行值

Sub RemoveDuplicates()
'UpdatebyExtendoffice20160918

    Dim xRow As Long
    Dim xCol As Long
    Dim xrg As Range
    Dim xl As Long
    On Error Resume Next
    Set xrg = Application.InputBox("Select a range:", "Kutools for Excel", _
                                    ActiveWindow.RangeSelection.AddressLocal, , , , , 8)

    xRow = xrg.Rows.Count + xrg.Row - 1
    xCol = xrg.Column
    'MsgBox xRow & ":" & xCol
    Application.ScreenUpdating = False
    For xl = xRow To 2 Step -1
        If Cells(xl, xCol) = Cells(xl - 1, xCol) Then
            Cells(xl, xCol) = ""
        End If
    Next xl
    Application.ScreenUpdating = True
    
End Sub

doc删除重复项以保持休息8

3。 按 F5 键运行代码,会弹出一个对话框,提醒您选择一个范围以从中删除重复的值。 看截图:
doc删除重复项以保持休息9

4。 点击 OK,现在已从选择中删除重复的值,并保留空白单元格。
doc删除重复项以保持休息10


使用 Kutools for Excel 删除重复项但保留其余行值

如果你有 Kutools 为 Excel –安装了方便且功能强大的添加工具,您可以通过两种方式快速删除重复项,但保留剩余值或行值。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

安装后 Kutools for Excel,请执行以下操作:(立即免费下载 Kutools for Excel!)

方法1:合并相同的单元格(2个步骤)

1.选择重复的值,然后单击 库工具 > 合并与拆分 > 合并相同的单元格。 看截图:
doc删除重复项以保持休息11

2.然后,重复值已合并到一个单元格中。 然后点击 主页 > 合并与中心 > 取消单元格拆分。 看截图:
doc删除重复项以保持休息12

现在结果显示如下:
doc删除重复项以保持休息13

方法2:选择重复和唯一单元格(4个步骤)

1.选择要从中删除重复项的数据列表,然后单击 库工具 > 选择 > 选择重复和唯一单元格。 看截图:
doc删除重复项以保持休息14

2.在 选择重复和唯一单元格 对话框,检查 重复(第一个除外) 在选项 部分。 看截图:
doc删除重复项以保持休息15

3。 点击 Ok,会弹出一个对话框,提醒您选择了多少个重复项,然后单击 OK 关闭它。 看截图:
doc删除重复项以保持休息16

4.然后按 删除 键以删除选定的重复值。

doc删除重复项以保持休息17

提示:Kutools for Excel高级组合行 实用程序,您可以组合重复的值,然后对另一列进行一些计算,如下图所示。 30天内全功能无限制,请下载并立即免费试用。
doc删除重复项以保持休息18

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

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

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (14)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
iNFORMATION IS VERY USEFUL.SAVED A LOT OF TIME

THANKS.
This comment was minimized by the moderator on the site
It help me after long search thank bro
This comment was minimized by the moderator on the site
Thank you so much! This was very helpful!!
This comment was minimized by the moderator on the site
i would use the formula =A3<>A2 (not equal to ) so that it show up on top vs. last one on bottom.
This comment was minimized by the moderator on the site
i tried the formula =A2=A1, it also got the result of show up on top.
This comment was minimized by the moderator on the site
i tried the formula =A1=A2, it also get the same result of show up on top
This comment was minimized by the moderator on the site
the true false really helped!
This comment was minimized by the moderator on the site
The True/False solution is a smart trick. Thanks
This comment was minimized by the moderator on the site
Is it possible to merge the like cells without the Kutools add-in?
This comment was minimized by the moderator on the site
This comment was minimized by the moderator on the site
In the first method, instead of =A3=A2, you can do =A2=A1 to keep the first instance and delete the rest of the duplicates.
This comment was minimized by the moderator on the site
yes it works
This comment was minimized by the moderator on the site
Thank you for this comment! Exactly what I was looking for!
This comment was minimized by the moderator on the site
Thank you for this tutorial, it saves me from tons of work removing duplicates.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations