|
Sub Macro1()
Dim arr, brr, sh As Worksheet, MyPath$, i&, lr&, m&, s$, a As Shape
Set sh = ActiveSheet
lr = Range("A65535").End(xlUp).Row
With Range("A5:AA" & lr)
.Sort Key1:=[b5].Resize(lr - 4), Order1:=xlAscending
arr = .Value
End With
ReDim brr(1 To UBound(arr), 1)
For i = 1 To lr - 4
If arr(i, 2) <> s Then
m = m + 1
brr(m, 0) = arr(i, 2)
brr(m, 1) = i + 4
s = arr(i, 2)
End If
Next
brr(m + 1, 1) = i + 4
MyPath = ThisWorkbook.Path & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 1 To m
sh.Copy
With ActiveSheet
.UsedRange.Offset(4).Clear
sh.Cells(brr(i, 1), 1).Resize(brr(i + 1, 1) - brr(i, 1), 27).Copy .[a5]
For Each a In .Shapes
a.Delete
Next
End With
ActiveWorkbook.SaveAs MyPath & brr(i, 0) & ".xls"
ActiveWorkbook.Close
Next
Application.ScreenUpdating = True
MsgBox "ok"
End Sub |
|