VLookup同一个人多个date

我有两个电子表格:

在这里输入图像描述

我想匹配两张表,并确保date匹配每个人。 例如,人1有三个不同的date,我想要他们完全匹配1:1。

人1,2015年3月2日(表A) – >人1,2015年3月2日(表B)
人1,2015年3月5日(表A) – >人1,3/5/2015(表B)
人1,2015年3月6日(表A) – >人1,3/6/2015(表B)

目前,我通过“否” 表A中的列,并在表B上使用Application.VLookup,但只有当Person只有一个date时才起作用。 否则,它将与表B中的第一个date进行比较。请参阅代码:

For sheetArowCounter= 2 To sheetAlastRow Sheets("A").Select sheetAperson = Cells(sheetArowCounter, 1) sheetAdate = Cells(sheetArowCounter, 2) Sheets("B").Select sheetBdate = Application.VLookup(sheetAperson, _ Sheets("B").Range(Cells(1, 1), Cells(sheetBLastRow, 2)), 2, False) If IsError(sheetBdate ) Then personFromTableAnotFound = personFromTableAnotFound + 1 ElseIf sheetBdate <> sheetAdate Then sheetAdateNotMatched = sheetAdateNotMatched + 1 End If sheetAdateCompared = sheetAdateCompared + 1 Next sheetArowCounter 

任何想法我怎么能做到这一点?

我同意上面的Jeeped。 尝试使用SUMIF。 您甚至可以在IF语句中嵌套SUMIF以返回文本:ie:“匹配”,“不匹配”

我会去一个countifs函数,它可以testing多列的标准。 这里是你如何在你的代码中实现这个例子:

 For sheetArowCounter = 2 To sheetAlastRow Sheets("A").Select sheetAperson = Cells(sheetArowCounter, 1) sheetAdate = Cells(sheetArowCounter, 2) Sheets("B").Select 'using the countifs function eg. =COUNTIFS(B!A3:A11,A!A3,B!B3:B11,A!B3) PersonDateMatches = Application.WorksheetFunction.CountIfs(Sheets("B").Range(Cells(1, 1), Cells(sheetBLastRow, 1)), sheetAperson, Sheets("B").Range(Cells(1, 2), Cells(sheetBLastRow, 2)), sheetAdate) If PersonDateMatches = 0 Then personDateFromTableAnotFound = personDateFromTableAnotFound + 1 End If sheetAdateCompared = sheetAdateCompared + 1 Next sheetArowCounter