|
Sub ADO_根据模板工作表_拆分工作表_固定行数()
Application.DisplayAlerts = False: Application.ScreenUpdating = False
If Worksheets.Count > 2 Then
For N = Worksheets.Count To 3 Step -1
Sheets(N).Delete
Next
End If
arr = Sheets("汇总").Range("a2:Y" & Sheets("汇总").[a65536].End(3).Row)
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
d(arr(i, 2) & "#" & arr(i, 16)) = ""
Next
ReDim brr(1 To d.Count, 1 To 2): crr = d.keys
For i = 1 To d.Count
brr(i, 1) = Split(crr(i - 1), "#")(0): brr(i, 2) = Split(crr(i - 1), "#")(1)
Next
Set cnn = CreateObject("adodb.connection"): Set rst = CreateObject("Adodb.Recordset")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=yes;IMEX=1';Data Source=" & ThisWorkbook.FullName
For i = 1 To d.Count
Sql = "Select 材料名称,规格型号,单位,SUM(净重),供货单位 from [汇总$a2:Y] where 日期=#" & brr(i, 1) & "# and 卸货地点='" & brr(i, 2) & "' GROUP BY 材料名称,规格型号,单位,供货单位"
rst.Open Sql, cnn, 1, 3
rst.PageSize = 10
For N = 1 To rst.PageCount
Sheets("每日材料进场").Copy After:=Sheets(Worksheets.Count)
Sheets(Worksheets.Count).Name = Year(brr(i, 1)) & "年" & Month(brr(i, 1)) & "月" & Day(brr(i, 1)) & "日" & brr(i, 2)
If rst.PageCount > 1 Then Sheets(Worksheets.Count).Name = Year(brr(i, 1)) & "年" & Month(brr(i, 1)) & "月" & Day(brr(i, 1)) & "日" & brr(i, 2) & "★" & N
rst.AbsolutePage = N
With Sheets(Worksheets.Count)
.Range("B4").CopyFromRecordset rst, rst.PageSize: .Range("E2") = brr(i, 1): .Range("B2") = brr(i, 2)
End With
Next
rst.Close
Next
Application.DisplayAlerts = True: Application.ScreenUpdating = True
End Sub |
评分
-
1
查看全部评分
-
|