|
Option Explicit
Sub TEST1()
Dim ar, br, i&, j&, strPat$, Matches As Object, aMatch As Object, dic As Object
ar = Worksheets(2).[A1].CurrentRegion.Value
For j = 1 To UBound(ar, 2)
strPat = ""
For i = 2 To UBound(ar)
If Len(ar(i, j)) Then strPat = strPat & "|" & ar(i, j)
Next i
ar(1, j) = Mid(strPat, 2)
Next j
With [A1].CurrentRegion
.Offset(1, 1).Clear
br = .Value
End With
Set dic = CreateObject("Scripting.Dictionary")
With CreateObject("VBScript.RegExp")
.Global = True
For j = 2 To 3
.Pattern = ar(1, j - 1)
For i = 2 To UBound(br)
If .test(br(i, 1)) Then
dic.RemoveAll
Set Matches = .Execute(br(i, 1))
For Each aMatch In Matches
dic(aMatch.Value) = Empty
Next
br(i, j) = Join(dic.keys, ",")
End If
Next i
Next j
End With
[A1].CurrentRegion.Value = br
Set Matches = Nothing: Set dic = Nothing
Beep
End Sub
|
评分
-
2
查看全部评分
-
|