|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'跟示例结果不同,规则有问题?
Option Explicit
Sub test()
Dim i, j, t, arr, brr, dic
Set dic = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
brr = Range("i2:i" & Cells(Rows.Count, "i").End(xlUp).Row)
For i = 1 To UBound(brr, 1)
If InStr(brr(i, 1), ";") Then
t = Split(brr(i, 1), ";")
For j = 0 To UBound(t): t(j) = seach(arr, t(j)): Next
brr(i, 1) = Join(t, ";")
Else
brr(i, 1) = seach(arr, brr(i, 1))
End If
Next
For i = 1 To UBound(brr, 1)
If InStr(brr(i, 1), ";") Then
dic.RemoveAll: t = Split(brr(i, 1), ";")
For j = 0 To UBound(t): dic(t(j)) = vbNullString: Next
brr(i, 1) = Join(dic.keys, ";")
End If
Next
[l2].Resize(UBound(brr, 1)) = brr
End Sub
Function seach(arr, s) As String
Dim i
For i = 2 To UBound(arr, 1)
If arr(i, 3) = s Then seach = seach & arr(i, 1) & ";"
Next
If Len(seach) Then seach = Left(seach, Len(seach) - 1)
End Function |
|