|
楼主 |
发表于 2012-3-25 08:56
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
jygzcj 发表于 2012-3-25 08:29
太猛了.达到我要的意思了!
Sub doryan()
Dim LstRow As Integer, Arr()
'建最后一行,一个动态数组
Dim Z%
Z = 1
'初始化Z
Dim sh As Worksheet
Set sh = Sheet1
With sh
LstRow = .[b65536].End(3).Row
'B列最后一行数
ReDim Arr(1 To LstRow, 1 To LstRow)
'扩展要分布的二维数组,等行等列
Arr(1, 1) = .Range("C2")
'将期初库存赋给arr(1,1)
For i = 2 To LstRow
Arr(1, i) = .Cells(i, 4)
Next
'接下Arr第一行用出库填充
'以下是重点语句
For r = 2 To LstRow
temp = .Range("E" & r)
For c = 1 To LstRow
c = Z
If temp <= Arr(1, Z) Then
Arr(r, c) = temp
Arr(1, Z) = Arr(1, Z) - temp
temp = 0
Exit For
Else
Arr(r, c) = Arr(1, Z)
temp = temp - Arr(1, Z)
Arr(1, Z) = 0
Z = Z + 1
End If
Next
Next
'----------------
.Range(.Cells(1, 8), .Cells(LstRow, LstRow + 7)) = Arr
For i = 1 To LstRow
If Arr(1, i) <> 0 Then
.Cells(1, i + 7) = .Cells(i, 2) & "入的,剩余" & Arr(1, i)
Else
.Cells(1, i + 7) = .Cells(i, 2) & "入的"
End If
Next
End With
End Sub
就这几句就搞定了.太猛了!再次感谢! |
|