如何在EXCEL的数据中导入到我自己设定的EXCEL模板中
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Option Explicit
Sub 生成标签()
Dim R As Long
Dim i As Long
Dim sht As Worksheet
Dim shtFrom As Worksheet
Dim shtMB As Worksheet
Dim toBK As Excel.Workbook
Dim FoundMB As Boolean
Dim FoundData As Boolean
For i = 1 To ThisWorkbook.Worksheets.Count
If ThisWorkbook.Worksheets(i).Name = "模板" Then FoundMB = True If ThisWorkbook.Worksheets(i).Name = "数据" Then FoundData = True Next
If FoundMB = False Or FoundData = False Then
MsgBox "找不到[模板]或[数据]工作表"
GoTo Exit_Sub
End If
Set shtMB = ThisWorkbook.Worksheets("模板")
Set shtFrom = ThisWorkbook.Worksheets("数据")
R = shtFrom.Range("A65536").End(xlUp).Row
Application.ScreenUpdating = False
Set toBK = Application.Workbooks.Add
For i = 2 To R Step 3
shtMB.Copy , toBK.Worksheets(toBK.Worksheets.Count)
Set sht = toBK.Worksheets(toBK.Worksheets.Count)
With sht
.Range("c1") = "'" & shtFrom.Cells(i, 1)
.Range("C3") = shtFrom.Cells(i, 2)
.Range("g5") = shtFrom.Cells(i, 3)
.Range("c19") = "'" & shtFrom.Cells(i + 1, 1)
.Range("C21") = shtFrom.Cells(i + 1, 2)
.Range("g23") = shtFrom.Cells(i + 1, 3)
.Range("c37") = "'" & shtFrom.Cells(i + 2, 1)
.Range("C39") = shtFrom.Cells(i + 2, 2)
.Range("g41") = shtFrom.Cells(i + 2, 3)
End With
= Right(shtFrom.Cells(i, 1), 5) & "-" & Right(shtFrom.Cells(i + 1, 1), 5) Next
On Error Resume Next
Application.ScreenUpdating = False
For i = 1 To 3
toBK.Worksheets("Sheet" & i).Visible = xlSheetVeryHidden
Next
Application.ScreenUpdating = True
ThisWorkbook.Worksheets(1).Select
'shtFrom.Select
Application.ScreenUpdating = True
Exit_Sub:
Set toBK = Nothing
End Sub