Excel vba使用2个标准记录行号

Excel vba使用2个标准记录行号,excel,vba,Excel,Vba,此代码用于查找一列中的重复项。我想找出重复使用2列。在本例中,我只需要在C列中记录第2行。第3行是正确的,因为他的第2列与第1行和第2行不同 使用带有两个条件的countif,而不是当前宏中的countif。另外,我使用cell作为变量名,这让你有点畏缩。。。 Dim cell As Range Dim duplicate_no As Long Dim ws As Worksheets duplicate_no = 2 With Intersect(ws.Columns("A"

此代码用于查找一列中的重复项。我想找出重复使用2列。在本例中,我只需要在C列中记录第2行。第3行是正确的,因为他的第2列与第1行和第2行不同


使用带有两个条件的
countif
,而不是当前宏中的
countif
。另外,我使用
cell
作为变量名,这让你有点畏缩。。。
Dim cell As Range
Dim duplicate_no As Long
Dim ws As Worksheets
duplicate_no = 2
With Intersect(ws.Columns("A"), ws.UsedRange)
    For Each cell In .Cells
        If WorksheetFunction.CountIf(.Resize(cell.Row - .Rows(1).Row + 1), cell.Value) > 1 Then
         Range("C" & duplicate_no).Cells = ("duplicate in " & cell.Address)
         duplicate_no = duplicate_no + 1
        End If
    Next cell
End With