|
楼主 |
发表于 2012-7-14 10:48
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 840205910 于 2012-7-14 10:58 编辑
网上搜到的,再整理了一下,还真可以达到先进先出的效果;不过毕竟是人家写的,吃进去了却不好消化,理解不了!
Private Sub Worksheet_Change(ByVal Target As Range)
lie = Target.Column
ha = Target.Row
If lie = 7 Or lie = 6 Then
Cells(ha, 8) = Cells(ha, 6) * Cells(ha, 7)
End If
If lie = 8 Then
If Cells(ha, 6) = 0 Then
Cells(ha, 7) = 0
Else
Cells(ha, 7) = Cells(ha, 8) / Cells(ha, 6)
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
wsh = ActiveCell.Row
If wsh < 6 Then
End
End If
If ActiveCell.Column = 6 And Cells(wsh, 1) = 0 Then
Cells(wsh, 1).Select
End If
If ActiveCell.Column = 10 Then
If Cells(wsh, 9) = 0 Then
Cells(wsh, 10) = 0
Cells(wsh, 11) = 0
Cells(wsh + 1, 1).Select
End
End If
'*************************
For a = wsh To 5 Step -1'按退一行的阶步从whs向上到5行
lja = lja + Cells(a, 6) '总进库数量
ca = lja - Cells(wsh, 12) '余库存数量
If ca > 0 Then
Exit For '退出循环
End If
Next
If ca >= Cells(wsh, 9) Then '余库存数量>=现出库数量
Cells(wsh, 11) = Cells(wsh, 9) * Cells(a, 7) '出库金额=出库数量*先进价格
Cells(wsh, 10) = Cells(wsh, 11) / Cells(wsh, 9)
Cells(wsh + 1, 1).Select
End
Else '否则的话
Cells(wsh, 11) = ca * Cells(a, 7) '出库金额=余库存数量*先进价格
Cells(wsh, 10) = Cells(wsh, 11) / Cells(wsh, 9)
End If
a = a - 1
'***************************
For b = a To 5 Step -1'按退一步的阶步从a到5行
ljb = ljb + Cells(b, 6)'不知如何理解
cb = ljb - (Cells(wsh, 9) - ca)'如何理解??????
If cb >= 0 Then
Exit For
End If
Next
Cells(wsh, 11) = Cells(wsh, 11) + WorksheetFunction.Sum(Range("h" & b & ":h" & a)) - cb * Cells(b, 7)'如何理解?????
Cells(wsh, 10) = Cells(wsh, 11) / Cells(wsh, 9)
Cells(wsh + 1, 1).Select
End If
'***************************************************
For Y = 5 To Range("a65536").End(xlUp).Row
If Range("f" & Y) + Range("i" & Y) = 0 Then
Range("l" & Y) = 0
Else
Range("l" & Y) = WorksheetFunction.Sum(Range("f" & 5 & ":f" & Y)) - WorksheetFunction.Sum(Range("i" & 5 & ":i" & Y))
End If
'*************
If Range("h" & Y) + Range("k" & Y) = 0 Then
Range("n" & Y) = 0
Else
Range("n" & Y) = WorksheetFunction.Sum(Range("h" & 5 & ":h" & Y)) - WorksheetFunction.Sum(Range("k" & 5 & ":k" & Y))
End If
'**************
If Range("l" & Y) = 0 Then
Range("m" & Y) = 0
Else
Range("m" & Y) = Range("n" & Y) / Range("l" & Y)
End If
Next
'********************************************************
End Sub |
|