Option Explicit
Sub TEST2()
Dim ar, br(), i&, j&, p&, r&, strFileName$, Rng As Range
Application.DisplayAlerts = False
With ActiveSheet.UsedRange
.Interior.Color = xlNone
ar = .Value: p = 1
For i = 2 To UBound(ar)
If i = UBound(ar) Then
r = r + 1
ReDim Preserve br(1 To 2, 1 To r)
br(1, r) = p: br(2, r) = i
Else
If ar(i + 1, 1) Like "A*" Then
r = r + 1
ReDim Preserve br(1 To 2, 1 To r)
br(1, r) = p: br(2, r) = i
p = i + 1
End If
End If
Next i
For j = 1 To UBound(br, 2)
strFileName = ThisWorkbook.Path & "\" & ar(br(1, j), 1)
Set Rng = .Cells(br(1, j), 1).Resize(br(2, j) - br(1, j) + 1, UBound(ar, 2))
With Workbooks.Add
Rng.Copy .Worksheets(1).[A1]
.SaveAs strFileName
.Close
End With
Next j
End With
Application.DisplayAlerts = True
Beep
End Sub
|