2010-03-24 37 views
1

我在Excel '07中有兩個名稱列表。每個文件中有兩列:名字和姓氏。我想要知道每個列表中的名稱(name = first,last)出現在另一個列表中。我能想到的任何方法都不能一次解釋多個專欄 - 例如,我可以看到有多少「史密斯」,有多少「阿爾伯特」,但我不知道有多少「阿爾伯特史密斯的有。在Excel中比較名稱列表,考慮重複的姓氏

想法?

編輯:顯然我可以連接,但我希望這種方法可推廣到兩列以上的數據。

回答

0

更新:想通了! Sumproduct爲我工作。這裏有一個公式:

=SUMPRODUCT(($G$8:$G$110=C28)*($F$8:$F$110=D28)) 

這假定基準名字都存儲在G,F中姓氏,而我要找的名稱是C(前)和分別d(最後)。輸出爲1表示匹配,0表示不匹配。只有在相鄰的單元匹配時纔會產生匹配。

0

最簡單的方法是使用CONCATENATE爲兩個列表創建第三列,然後使用此新列執行vlookup。

0

不幸的是,在Excel中這是一個非常常見的任務,其標準答案正如約書亞史密斯所說 - 通過連接可用列來構建組合鍵。如果擔心碰撞(例如,多列的直接連接可能會在相同輸出中留下不同的值),請使用分隔符(例如管道字符|)。


Col A Col B Col C Combined Key 
aaa  bbb  ccc aaabbbccc 
aa  aa  aaa aaaaaaa -- Bad match... 
aaa  a  aaa aaaaaaa -- Bad match... 

當然,您可以編寫自定義宏函數來爲您完成此操作。邏輯會是這樣的VLOOKUP

 
Public Function VMatch(ByVal lookFor As Range, ByVal lookIn As Range) As String 
    'Make sure column count matches (at least!) 
    If lookFor.Columns.Count lookIn.Columns.Count Then 
     'Oops... 
     VMatch = "ERROR: Column counts do not match" 
     Exit Function 
    End If 
    'Start looking through the target range for 
    'a match with the source range 
    Dim blnFound As Boolean 
    Dim blnRowOK As Boolean 
    blnFound = False 
    Dim iCol As Integer 
    Dim iRow As Long 
    Dim numCols As Integer 
    numCols = lookFor.Columns.Count 
    'Loop through all rows 
    For iRow = 1 To lookIn.Rows.Count 
     'Assume current row might be ok... 
     blnRowOK = True 
     'Loop through columns 
     For iCol = 1 To numCols 
      'Test for mis-match only 
      If lookFor.Cells(1, iCol).Value lookIn.Cells(iRow, iCol).Value Then 
       blnRowOK = False 
       Exit For 
      End If 
     Next 
     'If row is still ok, we've found a match! 
     If blnRowOK Then 
      blnFound = True 
      Exit For 
     End If 
    Next 
    'If blnFound is true, we found a match 
    If blnFound Then 
     VMatch = "Match" 
    Else 
     VMatch = "No Match" 
    End If 
End Function 

注:上述工程的功能和不容易受到「誤報」 - 它也試圖通過跳出如果它擊中一個配對的少,效率不高,但我不能不保證它在任何情況下都能正常工作。

要使用該函數,您需要將給定行上所有列的範圍引用爲lookFor,以及lookIn中所有可能的匹配行的整個範圍,例如, =VMatch(A1:C1,Sheet2!A1:C29)如果你匹配的事情是對當前工作表單元A1:C1和其他數據集是在Sheet2從第一行會下降到29行