|
- Sub test2() '拆分
- Dim r%, i%, m%
- Dim arr, brr, zrr()
- Dim wb As Workbook
- Dim ws As Worksheet
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Application.SheetsInNewWorkbook = 1
- With ThisWorkbook.Worksheets("sheet1")
- r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- c = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
- If r = 1 Then
- Exit Sub
- End If
- arr = .Range("a1").Resize(r, c)
- m = 0
- For i = 1 To UBound(arr)
- If Len(arr(i, 2)) = 0 Then
- m = m + 1
- ReDim Preserve zrr(1 To m)
- zrr(m) = Array(i, i)
- Else
- If m > 0 Then
- zrr(m)(1) = i
- End If
- End If
- Next
- For k = 1 To UBound(zrr)
- Set wb = Workbooks.Add
- With wb
- With .Worksheets(1)
- ThisWorkbook.Worksheets("sheet1").Cells(zrr(k)(0), 1).Resize(zrr(k)(1) - zrr(k)(0) + 1, c).Copy .Range("a1")
- End With
- .SaveAs Filename:=ThisWorkbook.Path & "" & arr(zrr(k)(0), 1)
- .Close False
- End With
- Next
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|