|
3学分
本帖最后由 18658662113 于 2021-5-23 08:36 编辑
一个箱子能装60片有的时候要改50 40都有 这个是变量不要固定
数量30=意思就是30片L 30片R 左右眼都要的
但愿能帮到你!
Sub 优先同产品()
Call wanao2008(True)
End Sub
Sub 直接按顺序()
Call wanao2008(False)
End Sub
Sub wanao2008(xlNum As Boolean)
Dim x As Integer, pNum As Integer, arr, xNum As Integer, hjNum As Integer
Dim xhStr As String
Sheet2.Activate
If [g2] = "" Then MsgBox "请输入每箱的片数": Range("G2").Select: Exit Sub
pNum = [g2]
Range("E2:F14").ClearContents
arr = Sheet2.UsedRange
If xlNum Then
For x = 2 To UBound(arr)
Do
If arr(x, 4) >= pNum Then
xNum = xNum + 1
If Cells(x, 5) <> "" Then
Cells(x, 5) = Cells(x, 5) & "," & xNum & "(" & Cells(x, 1) & "-" & pNum & ")"
Else
Cells(x, 5) = Cells(x, 5) & xNum & "(" & Cells(x, 1) & "-" & pNum & ")"
End If
arr(x, 4) = arr(x, 4) - pNum
Else
Exit Do
End If
Loop
Next
End If
For x = 2 To UBound(arr)
Do
If hjNum + arr(x, 4) >= pNum Then
xNum = xNum + 1
xhStr = xhStr & Cells(x, 1) & "-" & pNum - hjNum
arr(x, 4) = arr(x, 4) - (pNum - hjNum)
If Cells(x, 5) = "" Then
Cells(x, 5) = Cells(x, 5) & xNum & "(" & xhStr & ")"
Else
Cells(x, 5) = Cells(x, 5) & "," & xNum & "(" & xhStr & ")"
End If
hjNum = 0
xhStr = ""
Else
If arr(x, 4) <> 0 Then
hjNum = hjNum + arr(x, 4)
xhStr = xhStr & Cells(x, 1) & "-" & arr(x, 4) & ","
End If
Exit Do
End If
Loop
Next
If xhStr <> "" Then
xNum = xNum + 1
Mid(xhStr, Len(xhStr), 1) = ")"
Cells(x - 1, 5) = Cells(x - 1, 5) & xNum & "(" & xhStr
End If
'Stop
End Sub
|
最佳答案
查看完整内容
但愿能帮到你!
Sub 优先同产品()
Call wanao2008(True)
End Sub
Sub 直接按顺序()
Call wanao2008(False)
End Sub
Sub wanao2008(xlNum As Boolean)
Dim x As Integer, pNum As Integer, arr, xNum As Integer, hjNum As Integer
Dim xhStr As String
Sheet2.Activate
If [g2] = "" Then MsgBox "请输入每箱的片数": Range("G2").Select: Exit Sub
pNum = [g2]
Range("E2:F14") ...
|