|
Option Explicit
Sub TEST2()
Dim ar, i&, wks As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ar = [A1].CurrentRegion.Value
ar = cutArray(ar, 500)
With Workbooks.Add
For i = 1 To UBound(ar)
With .Worksheets.Add(after:=.Worksheets(.Worksheets.Count))
.Name = i
.[A1].Resize(UBound(ar(i)), UBound(ar(i), 2)) = ar(i)
End With
Next i
For Each wks In .Worksheets
If wks.Name Like "*Sheet*" Then wks.Delete
Next
End With
Application.DisplayAlerts = False
Application.ScreenUpdating = True
Beep
End Sub
Function cutArray(ByVal ar, ByVal iCutNum&) As Variant()
Dim br(), cr(), i&, j&, iPosRow&, r&, k&
For i = 1 To UBound(ar) Step iCutNum
iPosRow = IIf((i + iCutNum - 1) > UBound(ar), _
UBound(ar) Mod iCutNum, iCutNum)
ReDim cr(1 To iPosRow, 1 To UBound(ar, 2))
For j = 1 To UBound(cr)
For k = 1 To UBound(cr, 2)
cr(j, k) = ar(i - 1 + j, k)
Next k
Next j
r = r + 1
ReDim Preserve br(1 To r)
br(r) = cr
Next i
cutArray = br
End Function
|
|