查找并删除行中的重复单元格,而不是列

我目前有一个VBAmacros已经做到了,但并不完全是我所需要的。

这是VBA:

Sub StripRowDupes() Do Until ActiveCell = "" Range(ActiveCell, ActiveCell.End(xlToRight)).Select For Each Cell In Selection If WorksheetFunction.CountIf(Selection, Cell) > 1 Then Cell.ClearContents Else End If Next Cell On Error Resume Next Selection.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlToLeft ActiveCell.Range("A2").Select Loop End Sub 

而一个表单数据的例子( 是在每一行重复):

 A | B | C | D dog | cat | goat | dog car | ship | plane | ship 

运行这个macros后,它将从行中删除第一个重复实例,结果如下所示:

 A | B | C cat | goat | dog car | plane | ship 

我需要的是删除重复的最后一个实例,而不是第一个,得到以下结果:

 A | B | C dog | cat | goat car | ship | plane 

在当前的VBA脚本中更改什么来获得所需的结果?

UPD:

 Sub StripRowDupes() Dim c As Range, rng As Range Dim lastcol As Long Dim i As Long Dim rngToDel As Range, temp As Range Application.ScreenUpdating = False Set c = ActiveCell Do Until c = "" lastcol = Cells(c.Row, Columns.Count).End(xlToLeft).Column Set rng = c.Resize(, lastcol - c.Column + 1) For i = lastcol To c.Column Step -1 If WorksheetFunction.CountIf(rng, c.Offset(, i - 1)) > 1 Then c.Offset(, i - 1).ClearContents Next i On Error Resume Next Set temp = rng.SpecialCells(xlCellTypeBlanks) On Error GoTo 0 If Not temp Is Nothing Then If rngToDel Is Nothing Then Set rngToDel = temp Else Set rngToDel = Union(rngToDel, temp) End If End If Set c = c.Offset(1) Set temp = Nothing Loop If Not rngToDel Is Nothing Then rngToDel.Delete Shift:=xlToLeft Application.ScreenUpdating = True End Sub