|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- lk = Array(4, 32, 6, 8.13, 5.88, 10, 17)
- rq0 = Application.InputBox(prompt:="请输入送货日期(格式为:yyyymmdd)", Title:="操作提示", Default:=Format(Date, "yyyymmdd"), Type:=2)
- If Not IsDate(Format(rq0, "0000-00-00")) Then
- MsgBox "非规日期!"
- Exit Sub
- End If
- rq = CDate(Format(rq0, "0000-00-00"))
- If Dir(ThisWorkbook.Path & "\送货单", vbDirectory) = "" Then
- MkDir ThisWorkbook.Path & "\送货单"
- End If
- With ThisWorkbook.Worksheets("出货表")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:l" & r)
- End With
- For i = 1 To UBound(arr)
- If arr(i, 2) = rq Then
- If Not d.exists(arr(i, 3)) Then
- Set d(arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 3)).exists(arr(i, 1)) Then
- Set d(arr(i, 3))(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 3))(arr(i, 1))(i) = Empty
- End If
- Next
- For Each aa In d.keys
- Application.SheetsInNewWorkbook = d(aa).Count
- Set wb = Workbooks.Add
- p = 0
- With wb
- For Each bb In d(aa).keys
- p = p + 1
- With .Worksheets(p)
- .Name = aa & bb
- ReDim brr(1 To d(aa)(bb).Count, 1 To 7)
- M = 0
- For Each cc In d(aa)(bb).keys
- M = M + 1
- brr(M, 1) = M
- brr(M, 2) = arr(cc, 4)
- brr(M, 3) = arr(cc, 5)
- brr(M, 4) = arr(cc, 6)
- brr(M, 5) = arr(cc, 7)
- brr(M, 6) = arr(cc, 8)
- brr(M, 7) = arr(cc, 12)
- Next
- With .Range("a1")
- .Value = "送货单"
- .Resize(1, 7).Merge
- With .Font
- .Name = "Times New Roman"
- .Size = 20
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- .Rows(1).RowHeight = 45
- With .Range("a2")
- .Value = " 送货单号:" & bb
- .Resize(1, 4).Merge
- End With
- With .Range("e2")
- .Value = "送单日期:" & Format(rq, "yyyy年m月d日")
- .Resize(1, 3).Merge
- End With
- With .Range("a3")
- .Value = " 客户名称:" & aa
- .Resize(1, 4).Merge
- End With
- With .Range("e3")
- .Value = "制单日期:" & Format(Date, "yyyy年m月d日")
- .Resize(1, 3).Merge
- End With
- With .Range("a2:g3")
- With .Font
- .Name = "Times New Roman"
- .Size = 10
- .Bold = True
- End With
- End With
- With .Range("a2:d3")
- .HorizontalAlignment = xlLeft
- .VerticalAlignment = xlCenter
- End With
- With .Range("e2:g3")
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- With .Range("a4:g4")
- .Borders.LineStyle = xlContinuous
- .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
- .Value = Array("序号", "产品名称及型号", "单位", "数量", "单价", "金额", "备注")
- .Font.Bold = True
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- With .Range("a5").Resize(UBound(brr), UBound(brr, 2))
- .Value = brr
- .Borders.LineStyle = xlContinuous
- .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- With .Cells(4 + UBound(brr) + 1, 1)
- .Value = " 合计人民币金额(大写):" & dx(Application.Sum(Application.Index(brr, 0, 6)))
- .Resize(1, 5).Merge
- With .Font
- .Bold = True
- End With
- .HorizontalAlignment = xlLeft
- .VerticalAlignment = xlCenter
- End With
- With .Cells(4 + UBound(brr) + 1, 6)
- .Value = Application.Sum(Application.Index(brr, 0, 6))
- .Resize(1, 2).Merge
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .NumberFormatLocal = "0.00"
- End With
- With .Cells(4 + UBound(brr) + 1, 1).Resize(1, 7)
- .Borders.LineStyle = xlContinuous
- .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
- .Font.Bold = True
- End With
- With .Range("a4").Resize(1 + UBound(brr) + 1, UBound(brr, 2))
- With .Font
- .Name = "Times New Roman"
- .Size = 10
- End With
- End With
- With .Cells(4 + UBound(brr) + 1 + 2, 1)
- .Value = " 注:请收到本单后三日内核对,如有差异请告之,逾期以本单为准。"
- .Resize(1, 7).Merge
- With .Font
- .Name = "Times New Roman"
- .Size = 10
- End With
- .HorizontalAlignment = xlLeft
- .VerticalAlignment = xlCenter
-
- End With
- With .Cells(4 + UBound(brr) + 1 + 3, 1)
- .Value = Space(150) & "客户确认(签名):"
- .Resize(1, 7).Merge
- With .Font
- .Name = "Times New Roman"
- .Size = 10
- End With
- .HorizontalAlignment = xlLeft
- .VerticalAlignment = xlCenter
- End With
- .Rows(2).Resize(3 + UBound(brr) + 4).RowHeight = 15.75
- For j = 0 To UBound(lk)
- .Columns(j + 1).ColumnWidth = lk(j)
- Next
- End With
- Next
- .SaveAs Filename:=ThisWorkbook.Path & "\送货单" & aa & "(" & Format(rq, "yyyy年m月d日") & ")"
- .Close False
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "数据拆分完毕!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|