|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Dim arr: arr = Sheet1.Range("a1").CurrentRegion.Value
Dim dic: Set dic = CreateObject("scripting.dictionary")
Dim dic2: Set dic2 = CreateObject("scripting.dictionary")
Dim dic3: Set dic3 = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
s = arr(i, 3): s2 = arr(i, 2): ss = s & s2
If Not dic.exists(s) Then dic(s) = ""
If Not dic2.exists(s2) Then dic2(s2) = ""
If Not dic3.exists(ss) Then
dic3(ss) = arr(i, 1)
Else
dic3(ss) = dic3(ss) & ";" & arr(i, 1)
End If
Next i
ReDim crr(1 To dic.Count + 1, 1 To dic2.Count + 1)
crr(1, 1) = "职级"
m = 1
For Each k In dic.keys
m = m + 1
crr(m, 1) = k
Next
n = 1
For Each k2 In dic2.keys
n = n + 1
crr(1, n) = k2
Next
For x = 2 To UBound(crr)
For y = 2 To UBound(crr, 2)
t = crr(x, 1) & crr(1, y)
crr(x, y) = dic3(t)
Next y
Next
Sheet1.Range("f10").Resize(UBound(crr), UBound(crr, 2)) = crr
MsgBox "完成!"
End Sub |
|