当前位置: 首页 >>行业新风向 >>网站常见问题解答 >>在EXCE中通过VB脚本拆分大表并生成多个文件

在EXCE中通过VB脚本拆分大表并生成多个文件

时间:2020/8/19 2:37:00 【admin】

在EXCE中通过VB脚本拆分大表并生成多个文件…

Sub xxx()

Dim reg As Range

Dim i As Long

Dim x, pth As String

pth = ThisWorkbook.Path

 For i = 2 To 10000 Step 500

   Set reg = Nothing

   Set reg = Sheets("Sheet1").Rows(i & ":" & i + 499)

  x = Sheets("Sheet1").Cells(i, 1) & ""

  Sheets.Add.Name = x

  Sheets(x).[A1] = Sheets("Sheet1").[A1]

  Sheets(x).[B1] = Sheets("Sheet1").[B1]

  reg.Copy Sheets(x).Rows(2)

  Sheets(x).Copy

  Application.DisplayAlerts = False

  With ActiveWorkbook

    .SaveAs Filename:=pth & "\" & x & ".xlsx"

    .Close

  End With

  ThisWorkbook.Sheets(x).Delete

  Application.DisplayAlerts = True

 Next

End Sub


相关文章

CopyRight:2007-2018 语言吧 备案ICP:湘ICP备09009000号-15 http://www.yuyanba.com

分享按钮