我有两列,即A列和B列。
我的VBA宏应将2重复列出,但不应将1重复列出。请帮助
答案 0 :(得分:0)
假设您的键在 A 列中,值在 B 列中(均从第1行开始),请添加此公式...
=IsDuplicate(A:B,A1,B1)
...到单元格 C1 。
此代码应该有效...
Public Function IsDuplicate(ByVal rngAllData As Range, ByVal strKey As String, ByVal strValue As String) As Boolean
Dim lngBlanks As Long, objRow As Range, strThisKey As String, strThisValue As String, strFirstValue As String
Dim bFound As Boolean
Application.Volatile
For Each objRow In rngAllData.Rows
strThisKey = Trim(objRow.Cells(1, 1))
strThisValue = Trim(objRow.Cells(1, 2))
If strThisKey = "" Then
lngBlanks = lngBlanks + 1
Else
lngBlanks = 0
If strThisKey = strKey Then
If Not bFound Then
strFirstValue = strThisValue
If strValue = strFirstValue Then
IsDuplicate = False
Exit Function
Else
bFound = True
End If
Else
If strThisValue <> strFirstValue Then
IsDuplicate = True
Exit Function
End If
End If
End If
End If
If lngBlanks > 10 Then Exit For
Next
End Function
鉴于您的描述中有一些漏洞,我假设以下内容...
我希望有帮助。