|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 批量导出到模板3()
Dim ar, br, cr, i%, j%, wb1 As Workbook, wb2 As Workbook, wb As Workbook, d As Object
Set wb1 = ThisWorkbook
ar = wb1.Sheets("数据").Range("a2:bo" & Cells(Rows.Count, 1).End(xlUp).Row)
ReDim br(1 To UBound(ar) + 1, 1 To UBound(ar, 2))
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
br(1, j) = Replace(Cells(1, j).Address(False, False), "1", "") & "列"
br(i + 1, j) = ar(i, j)
Next j
Next i
Set wb2 = Workbooks.Open(wb1.Path & "\模板1.xls")
For m = 1 To UBound(ar)
For j = 2 To UBound(br, 2)
d(br(m + 1, 1) & "-" & br(1, j)) = br(m + 1, j)
Next j
Set wb = Workbooks.Add
wb2.Sheets.Copy before:=wb.Sheets(1)
With wb.Sheets("工作表1")
cr = .Range("a4:aa27")
For i = 1 To UBound(cr)
For j = 1 To UBound(cr, 2)
If Right(cr(i, j), 1) = "列" Then
.Cells(i + 3, j) = d(ar(m, 1) & "-" & cr(i, j))
Else
Select Case cr(i, j)
Case "第一学期"
For s = 1 To 6
.Cells(i + s + 2, j + 1) = ar(m, 2 * (s - 1) + 16)
.Cells(i + s + 2, j + 6) = ar(m, 2 * (s - 1) + 17)
Next s
Case "第三学期"
For s = 1 To 4
.Cells(i + s + 2, j + 1) = ar(m, 2 * (s - 1) + 38)
.Cells(i + s + 2, j + 4) = ar(m, 2 * (s - 1) + 39)
Next s
Case "第五学期"
For s = 1 To 3
.Cells(i + s + 2, j + 1) = ar(m, 2 * (s - 1) + 52)
.Cells(i + s + 2, j + 4) = ar(m, 2 * (s - 1) + 53)
Next s
Case "第二学期"
For s = 1 To 3
.Cells(i + s + 2, j + 1) = ar(m, 2 * (s - 1) + 28)
.Cells(i + s + 2, j + 6) = ar(m, 2 * (s - 1) + 29)
Next s
Case "第四学期"
For s = 1 To 3
.Cells(i + s + 2, j + 1) = ar(m, 2 * (s - 1) + 44)
.Cells(i + s + 2, j + 4) = ar(m, 2 * (s - 1) + 45)
Next s
Case "第六学期"
For s = 1 To 3
.Cells(i + s + 2, j + 1) = ar(m, 2 * (s - 1) + 58)
.Cells(i + s + 2, j + 4) = ar(m, 2 * (s - 1) + 59)
Next s
End Select
End If
Next j
Next i
.Cells(5, 10).Value = ar(m, 1)
End With
wb.SaveAs (wb1.Path & "\" & ar(m, 2) & ".xlsx")
wb.Close
d.RemoveAll
Next m
MsgBox "导出完毕!"
End Sub |
评分
-
2
查看全部评分
-
|