|
- Sub Demo()
- Dim i As Long, j As Long
- Dim arrData, rngData As range
- Dim arrRes, iR As Long, a, b
- Set oDicA = CreateObject("scripting.dictionary")
- Set oDicB = CreateObject("scripting.dictionary")
- Set rngData = ActiveSheet.range("A1").CurrentRegion
- arrData = rngData.value
- ReDim arrRes(1 To UBound(arrData) * 2, 1)
- iR = iR + 1
- arrRes(iR, 0) = arrData(1, 1)
- arrRes(iR, 1) = arrData(1, 2)
- ia = 1: iB = 1
- For i = LBound(arrData) + 1 To UBound(arrData)
- sKey = arrData(i, 1)
- If Len(sKey) > 0 Then oDicA(sKey) = ""
- sKey = arrData(i, 2)
- If Len(sKey) > 0 Then oDicB(sKey) = ""
- Next
- Do While oDicA.Count + oDicB.Count > 0
- If oDicA.Count Then a = oDicA.Keys()(0) Else a = ""
- If oDicB.Count Then b = oDicB.Keys()(0) Else b = ""
- If a = b Then
- iR = iR + 1
- arrRes(iR, 0) = a
- arrRes(iR, 1) = a
- oDicA.Remove (a)
- oDicB.Remove (b)
- ElseIf oDicB.exists(a) Or a = "" Or (Len(a) > 0 And b < a) Then
- iR = iR + 1
- arrRes(iR, 0) = ""
- arrRes(iR, 1) = b
- oDicB.Remove (b)
- ElseIf oDicA.exists(b) Or b = "" Or (Len(b) > 0 And a < b) Then
- iR = iR + 1
- arrRes(iR, 0) = a
- arrRes(iR, 1) = ""
- oDicA.Remove (a)
- End If
- Loop
- [H1].Resize(iR, 2).value = arrRes
- End Sub
复制代码 |
|