我有两个电子表格:
我希望匹配两张纸,并确保每个人的日期都匹配。例如。人1有三个不同的日期,我想完全匹配它们1:1。
人1,3/2/2015(表A) - >人1,3/2/2015(表B)
人1,3/5/2015(表A) - >人1,3/5/2015(表B)
人1,3/6/2015(表A) - >人1,3/6/2015(表B)
目前我循环通过" No。"表A中的列,并在表B上使用Application.VLookup,但仅当Person只有一个日期时才有效。否则,它将与表B中的第一个日期进行比较。请参阅代码:
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
知道我该怎么做?
答案 0 :(得分:1)
我同意上面的Jeeped。尝试使用SUMIF。您甚至可以将SUMIF嵌套在IF语句中以返回文本:ie:&#34; Match&#34;,&#34; No match&#34;
答案 1 :(得分:0)
我会选择一个countifs函数,可以测试多列的标准。以下是如何在代码中实现此功能的示例:
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