2017-04-04 76 views
0

我正在審查大量數據,指出存在不一致的地方。請參見下面的示例開始數據:刪除excel 2013中的重複項,並將所有來自第三個coulmn的所有項重複排列

enter image description here

這裏是我的目標是結果:

enter image description here

查詢我到目前爲止有:

=IF(AND(Sheet2!A2=Sheet2!A3,Sheet2!B2=Sheet2!B3),Sheet2!A2&Sheet2!B2&Sheet2!C2,"no match") 

哪有我將庫A和B匹配的所有結果連接在一起,刪除重複項,但也將C列中的所有結果連接起來,其中重複項將會已經進入那一行。

回答

0

如果您打開VBA解決方案,可以通過以下代碼輕鬆實現。 該代碼假定數據在列A:C中,row1是標題行。 輸出將寫入列E:G。您可以根據您的要求更改輸出位置。 如果需要,還可以將輸出寫回到所需格式的列A:C中。

Sub SummarizeData() 
Dim i As Long 
Dim x, y, dict, it 
Application.ScreenUpdating = False 

'clearing columns E:G before writing the output 
Columns("E:G").ClearContents 
x = Range("A1").CurrentRegion.Value 
Set dict = CreateObject("Scripting.Dictionary") 
For i = 1 To UBound(x, 1) 
    If dict.exists(x(i, 1) & ";" & x(i, 2)) Then 
     dict.Item(x(i, 1) & ";" & x(i, 2)) = dict.Item(x(i, 1) & ";" & x(i, 2)) & ", " & x(i, 3) 
    Else 
     dict.Item(x(i, 1) & ";" & x(i, 2)) = x(i, 3) 
    End If 
Next i 
i = 1 
ReDim y(1 To dict.Count, 1 To 3) 
For Each it In dict.keys 
    y(i, 1) = Split(it, ";")(0) 
    y(i, 2) = Split(it, ";")(1) 
    y(i, 3) = dict.Item(it) 
    i = i + 1 
Next it 
'Writing the output in columns E:G 
Range("E1").Resize(dict.Count, 3).Value = y 
Application.ScreenUpdating = True 
End Sub