|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Column = 7 Then
- Product = Range("C" & Target.Row).Value
- ar = GetList(Product)
- Range("G:j").ClearContents
- Target.Resize(UBound(ar), 4).Value = ar
- End If
- End Sub
- Function GetList(P0)
- With Sheet1
- r = .Cells(.Rows.Count, 2).End(3).Row
- ar = .Range("A1:F" & r).Value
- End With
- Dim d As New Dictionary
- ReDim br(0 To r, 1 To 4)
- br(0, 1) = "批号": br(0, 3) = "剩余库存"
- For i = 2 To UBound(ar)
- If ar(i, 3) = P0 Then
- If ar(i, 4) = "入库" Then '先入库才有出库
- code = ar(i, 6)
- If Not d.Exists(code) Then
- j = j + 1
- br(j, 1) = code
- br(j, 3) = ar(i, 5)
- Else
- k = d(code)
- br(k, 3) = br(k, 3) + ar(i, 5)
- End If
- Else '出库
- v = ar(i, 5)
- For k = 1 To j
- If br(k, 3) >= v Then '出库结束
- br(k, 3) = br(k, 3) - v
- Exit For
- Else '先进的先出
- v = v - br(k, 3)
- br(k, 3) = 0
- End If
- Next
- End If
- End If
- Next
- GetList = br
- End Function
复制代码 |
|