|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 wqhsz385919 于 2024-2-17 14:09 编辑
配单.7z
(27.32 KB, 下载次数: 6)
你好!请帮忙看下,按出货的数量找未清订单明细里凑单,按订单的先后顺序,自己学着写,中间逻辑实在想不到,请大侠帮忙指导,谢谢!
举例:采购工厂&料号 出货1000,就在未清订单明细里找到这个采购工厂&料号,数量刚好1000,附件有手工模拟的结果
以上谢谢!
以下是自己学着写的代码:
Sub peidan()
Dim brr(1 To 1000, 1 To 14)
Set d = CreateObject("scripting.dictionary")
With Sheets("未清订单")
cr = .Range("a1").CurrentRegion
End With
With Sheets("明天出货")
ar = .Range("a1").CurrentRegion
For i = 2 To UBound(ar)
s = ar(i, 2) & "@" & ar(i, 6)
d(s) = d(s) + ar(i, 9)
Next
End With
k0 = d.keys
For Each kk In k0
For i = 2 To UBound(cr)
s = cr(i, 9) & "@" & cr(i, 5)
If d.exists(s) Then
If cr(i, 7) - d(kk) < 0 Then
k = k + 1: ss = ss + cr(i, 7)
If ss < d(kk) Then
For j = 1 To 14
brr(k, j) = cr(i, j)
Next
End If
brr(k, 7) = cr(i, 7)
Else
k = k + 1
For j = 1 To 14
brr(k, j) = cr(i, j)
Next
brr(k, 7) = d(kk)
Exit For
End If
End If
Next
Next
With Sheets("出货配单")
.UsedRange.Offset(1).Clear
.AutoFilterMode = False
.Columns(3).NumberFormatLocal = "@"
With .Range("a2").Resize(k, 14)
.Value = brr
.Borders.LineStyle = 1
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Name = "等线"
.Font.Size = 9
End With
End With
End Sub
|
|