|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub TEST()
Dim ar, br, i&, n&, dic As Object, vKey, t#
Dim strFileName$, strPath$, strName$, wks As Worksheet
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "签收单模板.xlsx"
If Dir(strFileName) = "" Then MsgBox "模板文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
t = Timer
Set dic = CreateObject("Scripting.Dictionary")
ar = [A1].CurrentRegion
For i = 2 To UBound(ar)
vKey = ar(i, 19)
dic(vKey) = dic(vKey) & " " & i
Next i
With GetObject(strFileName)
Set wks = .Sheets(1)
For Each vKey In dic.keys
br = Split(dic(vKey)): n = 0
For i = 1 To UBound(br)
n = n + ar(br(i), 9)
Next i
wks.Copy
strName = strPath & "签收单\" & vKey & "签收单"
With ActiveWorkbook
With .Sheets(1)
.Cells(2, 1) = ar(br(1), 1)
.Cells(2, 2) = ar(br(1), 11)
.Cells(2, 3) = vKey
.Cells(2, 4) = n
.Cells(3, 3) = ar(br(1), 12)
End With
.SaveAs strName
.Close
End With
Next
.Close False
End With
Set dic = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
|
|