我試圖刪除單個列中重複單元格的內容。我想保留條目的第一個匹配項,但刪除它下面的所有重複項。刪除列中的重複單元格內容
我只能找到刪除整行並且不清除內容的代碼。
Sub Duplicate()
With Application
' Turn off screen updating to increase performance
.ScreenUpdating = False
Dim LastColumn As Integer
LastColumn = Cells.Find(What:="*", After:=Range("U1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
With Range("U1:U" & Cells(Rows.Count, 1).End(xlUp).Row)
' Use AdvanceFilter to filter unique values
.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
.SpecialCells(xlCellTypeVisible).Offset(0, LastColumn - 1).Value = 1
On Error Resume Next
ActiveSheet.ShowAllData
'Delete the blank rows
Columns(LastColumn).SpecialCells(xlCellTypeBlanks).Cells.Clear
Err.Clear
End With
Columns(LastColumn).Clear
.ScreenUpdating = True
End With
End Sub
只是使用任何算法顯示檢測重複單元格,然後,而不是使用'wholerow.delete'方法,使用'cells.clear'方法。如果它不起作用,請發佈您的代碼。 –
@RonRosenfeld我只能找到刪除所有條目並且不保留第一個出現的代碼。我編輯了我的帖子以顯示我正在嘗試使用的代碼。 –
我已經發布了一些可以使用的東西,它使用了不同的算法。高級過濾器似乎不適合您的目的。 –