Dim ar, br, r, i, k, wb, d, m, n
k = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
With Sheet1.Sort
.SortFields.Add Key:=Sheet1.Range("B2:B" & k)
.SortFields.Add Key:=Sheet1.Range("J2:J" & k)
.SortFields.Add Key:=Sheet1.Range("K2:K" & k)
.SetRange Range("A1:T" & k)
.Header = xlYes
.Apply
End With
ar = Sheet1.[a1].CurrentRegion
br = Sheet2.Range("A1:X" & k)
Set d = CreateObject("scripting.dictionary")
Set r = CreateObject("vbscript.regexp")
r.Pattern = "\x5b.+\x5d|\x28.+\x29|SQ|AWG|1X"
r.Global = True
For i = 2 To k
br(i, 1) = Split(ar(i, 19), "-")(0)
br(i, 2) = Format(Split(ar(i, 19), "-")(1), "00000")
br(i, 6) = ar(i, 15)
br(i, 17) = Int(ar(i, 11))
br(i, 18) = ar(i, 3)
br(i, 19) = Left(ar(i, 3), 4) + 1 & Right(ar(i, 3), 4)
br(i, 21) = Right(ar(i, 2), 2) & " " & r.Replace(ar(i, 10), "")
br(i, 24) = Right(ar(i, 2), 2)
d(br(i, 24)) = 1
Next i
Sheet2.Range("X2:X" & k).NumberFormatLocal = "@"
Sheet2.[a1].Resize(k, 24) = br
For Each m In d.keys
Set wb = Workbooks.Add
With wb.Sheets(1)
.Cells.NumberFormatLocal = "@"
.[a1].Resize(1, 24) = Application.Index(br, 1, 0)
n = 1
For i = 2 To k
If br(i, 24) = m Then
n = n + 1
For j = 1 To 24
.Cells(n, j) = br(i, j)
Next j
End If
Next i
End With
wb.SaveAs ThisWorkbook.Path & "\" & m & ".xlsx"
wb.Close
Next m |