I have two columns, Column A and column B.
My VBA macro should list 2 as a duplicate but should not list 1 as a duplicate.Pls help
Assuming your keys are in column A and values in column B (both starting from row 1), add this formula ...
=IsDuplicate(A:B,A1,B1)
... to cell C1 .
This code should work ...
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
Given there are a few holes in your description, I've assumed the following ...
I hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.