|
Sub 按行拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long
Dim br(), cr()
Dim rn As Range
With ActiveSheet
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:d" & r)
Set rn = .Rows(1)
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 1 To UBound(ar)
If ar(i, 1) <> "" Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
End If
Next i
End With
lj = ThisWorkbook.Path & "\拆分文件\"
Application.SheetsInNewWorkbook = 1
For i = 2 To n Step 10000
m = 0: k = k + 1
ReDim cr(1 To UBound(ar), 1 To UBound(ar, 2))
For s = i To i + 9999
If s <= n Then
m = m + 1
For j = 1 To UBound(br, 2)
cr(m, j) = br(s, j)
Next j
End If
Next s
Set wb = Workbooks.Add
With wb.Worksheets(1)
.Name = k
.Columns(3).NumberFormatLocal = "@"
rn.Copy .[a1]
.[a2].Resize(m, UBound(cr, 2)) = cr
.Columns("a:c").AutoFit
End With
wb.SaveAs Filename:=lj & k & ".xlsx"
wb.Close
Next i
Application.ScreenUpdating = True
MsgBox "共拆分了" & k & "个文件!"
End Sub
|
|