求EXCEL VBA代码类似规划求解凑数,填入对应数据,可留邮箱转发附件,如图片说明需求,源数据不固定,谢谢!

2024-12-01 18:16:42
推荐回答(2个)
回答1:

不算太难,可以试试,留你邮箱。。。
可以了,你自己再微调下,下班啦

Sub Test1()
Dim Cnt1, Cnt2 As Integer
Dim i, j, j0, k As Integer
i = 2
j = 2
Cnt1 = Cells(2, 12)
Do While Cnt1 <> ""
j0 = j
Cnt2 = 0
Do While Cnt2 < Cnt1
Cnt2 = Cnt2 + Cells(j, 4)
j = j + 1
Loop
If Cnt2 = Cnt1 Then
For k = j0 To j
Cells(k, 3) = Cells(i, 9)
Next k
End If
If Cnt2 > Cnt1 Then
Cells(i, 13) = "未分配"
j = j - 1
End If
i = i + 1
Cnt1 = Cells(i, 12)
Loop
End Sub

回答2:

317403844@qq.com