|
本帖最后由 driveyin 于 2018-7-12 21:04 编辑
求助各位大神,
Sub SplitExl()
Application.DisplayAlerts = False '新建的文档存在时,不发送警示,覆盖式保存
Dim lngRs&, lngCs&, cx&, strEndCl$
Dim topR(), EveryR(), oExl As Object, oWk As Workbook
Dim strPath$
strPath = ThisWorkbook.Path & "\"
With ActiveSheet.UsedRange
lngRs = .Rows.Count
lngCs = .Columns.Count
End With
strEndCl = Replace(Replace(Cells(1, lngCs).Address, "$", ""), "1", "")
topR = Range("A1:" & strEndCl & "1") '数据标题行
For cx = 2 To lngRs
EveryR = Range("A" & Format(cx) & ":" & strEndCl & Format(cx)) '把每行记录放入数组
Set oWk = Application.Workbooks.Add
With oWk
'.Parent.Visible = True
With .Sheets(1)
.Range("A1:" & strEndCl & "1") = topR '把标题行放入另建的工作薄
.Range("A2:" & strEndCl & "2") = EveryR '把单个记录放入同一另建的工作薄
End With
.SaveAs Filename:=strPath & EveryR(1, 7) & ".xls" '以每行A列记录为工作薄名称
.Close
End With
Next
Set oWk = Nothing
Set oExl = Nothing
Erase topR: Erase EveryR
Application.DisplayAlerts = True
End Sub
通过这个代码可以拆分表内每行,但是我的工作薄里还有一个SHEET2需要复制到拆分的表里(同样是SHEET2),在这个代码基础上怎么实现
|
|