跳到主要內容

如何刪除重複項,但保留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 for Applications 窗口。

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 –安裝了方便且功能強大的插件工具,您可以通過兩種方式快速刪除重複項,但保留剩餘值或行值。

Excel的Kutools, 與以上 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

小提示: with Excel的Kutools高級合併行 實用程序,您可以組合重複的值,然後對另一列進行一些計算,如下圖所示。 30天內全功能無限制,請下載並立即免費試用。
doc刪除重複項以保持休息18

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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