一个工作薄按照固定数量分割成N个工作薄

2018年1月24日16:10:51 发表评论 830 views

Sub 分表()
Dim cellall As Integer
FILENAMEA = ThisWorkbook.Name
Windows(FILENAMEA).Activate
Application.ScreenUpdating = False   '关闭屏幕刷新
Application.DisplayAlerts = False '不进行警告确认
cellall = Application.WorksheetFunction.CountA(Sheets(1).Columns(1)) '数据表第一列不能为空否则将Columns(1)中的1修改为没有空格的列
a = 1
For i = 1 To Int(cellall / 100) + 1
Workbooks.Add

ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & "数据表" & i & ".xls", FileFormat:=xlExcel8, ReadOnlyRecommended:=False, _

CreateBackup:=False

Windows(FILENAMEA).Activate

' Sheets("数据表").Rows(1).Copy Workbooks("数据表" & i & ".xls").Sheets(1).Rows(1)

Sheets("数据表").Range(Sheets("数据表").Rows(a), Sheets("数据表").Rows(a + 99)).Copy Workbooks("数据表" & i & ".xls").Sheets(1).Cells(1, 1)

a = a + 100

Windows("数据表" & i & ".xls").Activate

ActiveWindow.Close (True)

Next i

 

 

 

Application.ScreenUpdating = True  '开启屏幕刷新

Application.DisplayAlerts = True '进行警告确认

Windows(FILENAMEA).Activate

 

本文是全系列中第3 / 9篇:Excel

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: