|
- Sub 拆分()
- Dim arr
- Dim wb As Workbook
- Dim ws As Worksheet
- Set ws = ThisWorkbook.Worksheets("模板")
- arr = Worksheets("数据源").Range("A2:G3") '指定固定区域
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For i = 1 To UBound(arr)
- With ws
- .Range("C2,E2,C3,E3,C4:E4,C5,E5").ClearContents '先消除模板中指定区域的内容;若有合并单元格时地址写法注意,如这里“C4:E4”就是合并单元格
- .Range("C2") = arr(i, 2)
- .Range("E2") = arr(i, 4)
- .Range("C3") = arr(i, 3)
- .Range("E3") = arr(i, 1)
- .Range("C4") = arr(i, 5)
- .Range("C5") = arr(i, 7)
- .Range("E5") = arr(i, 6)
- End With
- ws.Copy
- With ActiveWorkbook
- .SaveAs Filename:=ThisWorkbook.Path & "" & arr(i, 2) '工作薄名称,以姓名列
- .Close False
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "数据拆分完毕!"
- ThisWorkbook.Worksheets("模板").Range("C2,E2,C3,E3,C4:E4,C5,E5").ClearContents '先消除模板中指定区域的内容;若有合并单元格时地址写法注意,如这里“C4:E4”就是合并单元格
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|