|
楼主 |
发表于 2023-3-2 22:41
|
显示全部楼层
Sub 批量生成入库单()
Application.ScreenUpdating = False
Dim dqsh As Worksheet, fzmb As Worksheet, mb As Worksheet, sxrg As Range
Dim wb As Workbook, y%, r%, x%, k%, i%, d, arr, arr1, m%
t = Timer
Set d = CreateObject("scripting.dictionary")
Set rksh = Sheets("入库明细")
Set mb = Sheets("入库单模板")
rksh.AutoFilterMode = False
r = rksh.Range("b65536").End(xlUp).Row
arr = rksh.Range("T2:T" & r)
For x = 1 To UBound(arr)
d(arr(x, 1)) = ""
Next x
arr1 = Application.Transpose(d.keys)
For k = 1 To UBound(arr1)
rksh.Range("a1").AutoFilter 20, arr1(k, 1)
i = rksh.Range("B2:B" & r).SpecialCells(xlCellTypeVisible).Cells.Count
mb.Copy after:=Sheets(Sheets.Count)
Set fzmb = ActiveSheet
fzmb.Name = arr1(k, 1) '改名字
fzmb.Range("b9").Resize(i).EntireRow.Insert '插入行
' 格式刷
' Rows("8:8").Select
' Selection.Copy
' Range("b9:b" & i + 9).EntireRow.Select
' Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
' SkipBlanks:=False, Transpose:=False
' Application.CutCopyMode = False
' Range("c9").Select
' '复制数据到模板
brr = rksh.Range("a1").CurrentRegion
' sxrg.Offset(1, 0).Resize(sxrg.Rows.Count - 1).Copy fzmb.Range("c9") '怎么复制数据粘贴到有合并的单元格?
' fzmb.Range("l" & i + 9) = "=sum(l9:l" & i + 8 & ")" '税金
' fzmb.Range("h" & i + 9) = "=sum(h9:h" & i + 8 & ")" '数量
' fzmb.Range("M" & i + 9) = "=sum(M9:M" & i + 8 & ")" '非税金额
' fzmb.Range("O" & i + 9) = "=sum(O9:O" & i + 8 & ")" '含税金额
' For m = 1 To i
' fzmb.Range("b" & m + 8) = m '添加序号
' Next m
fzmb.Range("d4") = brr(k + 1, 20) '入库单号
fzmb.Range("d5") = brr(k + 1, 2) '供应商名称
fzmb.Range("d6") = brr(k + 1, 24) '采购员
fzmb.Range("k4") = brr(k + 1, 18) '入库仓库
fzmb.Range("k5") = Format(brr(k + 1, 19), "0.00") '税率,还没解决0.00
fzmb.Range("k6") = brr(k + 1, 23) '质检单号
fzmb.Range("p4") = brr(k + 1, 21) '入库方式
fzmb.Range("p5") = brr(k + 1, 22) '入库日期
fzmb.Range("p6") = brr(k + 1, 22) '制单日期
y = y + 1
Next k
Sheets("入库单模板").Select
Sheets("入库明细").AutoFilterMode = False
Application.ScreenUpdating = True
MsgBox "入库单已处理完成,一共生成" & y & "个入库单,一共用时" & Timer - t & "秒"
End Sub |
|