Try this:
- Sub zz()
- Dim ar, a(), br(), d, k, t, TL, tt
- Set d = CreateObject("scripting.dictionary")
- ar = [a1].CurrentRegion
- a = Array(2, 6, 4, 5, 5, 8, 7)
- For i = 0 To UBound(a)
- TL = TL & "|" & ar(1, a(i))
- Next
- TL = Split(Mid(TL, 2), "|")
- For i = 2 To UBound(ar)
- t = ""
- For j = 0 To UBound(a)
- t = t & "|" & ar(i, a(j))
- Next
- d(ar(i, 2)) = d(ar(i, 2)) & "@" & t
- Next
- t = d.items
- For i = 1 To d.Count
- Workbooks.Add
- [a1].Resize(1, UBound(TL) + 1) = TL
- ar = Split(t(i - 1), "@")
- ReDim br(1 To UBound(ar), 1 To UBound(a) + 1)
- For ii = 1 To UBound(ar)
- k = Split(ar(ii), "|")
- For j = 1 To UBound(k)
- If j <> 5 Then br(ii, j) = k(j)
- Next
- Next
- [a2].Resize(UBound(br), UBound(br, 2)) = br
- [e1] = "Unit"
- ActiveWorkbook.SaveAs ThisWorkbook.Path & "" & br(1, 1)
- Next
- Set d = Nothing
- End Sub
复制代码 |