仅删除可见行的可见重复项

新的在VBA。 我正在使用下面的代码来标识和删除Sheet1中的行在Sheet2的列C中具有重复值的行,但我需要的代码不会删除已从filter隐藏的行。

我搜查了四周,并尝试使用.SpecialCells(xlCellTypeVisible),但我不知道在哪里放置它。 我认为另一种select是使用EntireRow.Hidden语法,但我不知道如何合并。

任何帮助表示赞赏。

Sub DeleteDuplicates() Application.ScreenUpdating = False Dim Row As Long Dim FoundDup As Range Sheets("Sheet1").Select For Row = Range("C65536").End(xlUp).Row To 2 Step -1 Set FoundDup = Sheets("Sheet2").Range("C:C").Find(Cells(Row, 3), LookIn:=xlValues, lookat:=xlWhole) If Not FoundDup Is Nothing Then Cells(Row, 3).EntireRow.Delete End If Next Row Application.ScreenUpdating = True End Sub 

给你的If语句添加一个额外的条件:

If Not FoundDup Is Nothing And Not Cells(Row,3).EntireRow.Hidden Then