|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
试试这个
- Sub t2()
- Dim dic, m%, arr, brr, r%, c1%, c2%, c3%, c4%, b, i%, til
- Set dic = CreateObject("scripting.dictionary")
- With Sheets("原数据")
- m = .[a3].End(4).Row
- ss = .Range("a2:b" & m).Sort(key1:="品名", key2:="型号", Header:=xlYes)
- arr = .Range("a3:b" & m)
- End With
- til = Array("品名", "区域A", "区域B", "区域C", "区域D")
- For i = 1 To UBound(arr)
- dic(arr(i, 1)) = dic(arr(i, 1)) & "|" & arr(i, 2)
- Next i
- ReDim brr(1 To 100, 1 To 5)
- r = 2
- For Each k In dic.keys
- brr(r, 1) = k
- b = Split(dic(k), "|")
- c1 = 0: c2 = 0: c3 = 0: c4 = 0
- brr(r, 1) = k
- For i = 1 To UBound(b)
- If r - 1 = 1 Then brr(r - 1, i) = til(i - 1)
- If InStr(b(i), "a") Then
- brr(r, 1) = k
- brr(r, 2) = brr(r, 2) + b(i) + " "
- ElseIf InStr(b(i), "b") Then
- brr(r, 1) = k
- brr(r, 3) = brr(r, 3) + b(i) + " "
- ElseIf InStr(b(i), "c") Then
- brr(r, 1) = k
- brr(r, 4) = brr(r, 4) + b(i) + " "
- ElseIf InStr(b(i), "d") Then
- brr(r, 1) = k
- brr(r, 5) = brr(r, 5) + b(i) + " "
- End If
- Next i
- r = r + 1
- Next k
- Sheets("目标表样").[g2].Resize(UBound(brr), 5) = brr
- End Sub
复制代码 |
|