|
以下是请人帮忙写的一段代码,求翻译,方便以后出现问题时好处理。请一条一条的翻译。
Sub 填写运单()
Dim sh As Worksheet, d As Object, arr As Variant, i, x, k, br(), m, brr(1 To 7)
arr = Sheet2.[A1].CurrentRegion
If UBound(arr) < 2 Then MsgBox "请检查【数据源】表无数据,程序退出!", 64, "温馨提示": Exit Sub
Application.DisplayAlerts = False
MMBW
Application.DisplayAlerts = True
tim = Timer
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
If arr(i, 11) <> "" Then d(Trim(arr(i, 11)) & "+" & Trim(arr(i, 2))) = ""
Next i
k = d.keys
For x = 0 To UBound(k)
Set sh = Worksheets.Add(after:=Sheets(Sheets.Count))
sh.Name = Split(k(x), "+")(0) & "-" & x
Sheet1.[A1:XFD1048576].Copy sh.[A1:XFD1048576]
m = 0: qa = 0: qb = 0: qc = 0
For i = 2 To UBound(arr)
If Trim(arr(i, 11)) & "+" & Trim(arr(i, 2)) = k(x) Then
m = m + 1
ReDim Preserve br(1 To 3, 1 To m)
br(1, m) = arr(i, 1): br(2, m) = arr(i, 6): br(3, m) = arr(i, 18)
brr(1) = arr(i, 11): brr(2) = arr(i, 2): brr(3) = arr(i, 24): brr(4) = arr(i, 25)
qa = qa + arr(i, 20): qb = qb + arr(i, 19): qc = qc + arr(i, 18)
End If
Next
brr(5) = qa: brr(6) = qb: brr(7) = qc
n = n + 1
sh.[I2] = "BJSF" & Year(Now()) & Format(Month(Now()), "00") & Format(Day(Now()) + 1, "00") & Format(n, "0000")
sh.[C4].Resize(7, 1) = Application.Transpose(brr)
sh.[B14].Resize(m, 3) = Application.Transpose(br)
d.RemoveAll
Next
MsgBox Format(Timer - tim, "共有 " & n & " 张【交接单】填写完成,耗时:0.00秒"), 64, "温馨提示"
Application.ScreenUpdating = True
End Sub
Sub MMBW()
Application.DisplayAlerts = False
For Each sh In Worksheets
If sh.Name <> "运单模板" And sh.Name <> "数据源" And sh.Name <> "取货明细" Then sh.Delete
Next sh
Application.DisplayAlerts = True
End Sub
|
|