|
参与一下- Sub t()
- 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
- If c1 > 0 Then brr(r + c1, 1) = k
- brr(r + c1, 2) = b(i): c1 = c1 + 1
- ElseIf InStr(b(i), "b") Then
- If c2 > 0 Then brr(r + c2, 1) = k
- brr(r + c2, 3) = b(i): c2 = c2 + 1
- ElseIf InStr(b(i), "c") Then
- If c3 > 0 Then brr(r + c3, 1) = k
- brr(r + c3, 4) = b(i): c3 = c3 + 1
- ElseIf InStr(b(i), "d") Then
- If c4 > 0 Then brr(r + c4, 1) = k
- brr(r + c4, 5) = b(i): c4 = c4 + 1
- End If
- Next i
- r = r + WorksheetFunction.Max(c1, c2, c3, c4)
- Next k
- Sheets("目标表样").[g3].Resize(UBound(brr), 5) = brr
- End Sub
复制代码 |
|