|
楼主 |
发表于 2021-1-14 14:48
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 早餐配送()
Dim Arr, brr, crr, drr, d As Object, rr%, i%, j%, m%, n%, r%, t%, d1 As Object, d2 As Object
On Error Resume Next
t = Application.CountA(Sheets("就餐人数").[A5:A73]) - 1
Sheets("配送数据").Rows("2:50000").ClearContents
Arr = Sheets("一周菜谱").[A1].CurrentRegion
brr = Sheets("菜谱库").[A1].CurrentRegion
drr = Sheets("就餐人数").[A1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For r = 5 To t + 5
For rr = 3 To UBound(Arr, 1) Step 5
For i = 0 To 4
For j = 2 To UBound(Arr, 2)
If Arr(rr + i, j) <> "" Then
For m = 2 To UBound(brr)
If Arr(rr + i, j) = brr(m, 2) Then
crr = Split(brr(m, 3), ";")
For n = 0 To UBound(crr)
d(Split(crr(n), ",")(0)) = d(Split(crr(n), ",")(0)) + Val(Split(crr(n), ",")(1)) * drr(r, j + 3) / 500
Next n
End If
Next m
End If
Next j
Next i
With Sheets("配送数据")
m = Application.CountA(.[E:E])
n = Application.CountA(.[D:D])
Sheets("配送数据").Cells(m + 1, 5).Resize(d.Count) = Application.Transpose(d.keys)
Sheets("配送数据").Cells(m + 1, 7).Resize(d.Count) = Application.Transpose(d.items)
Sheets("配送数据").Range("b" & m + 1 & ":b" & r) = Sheets("就餐人数").Range("b3")
Sheets("配送数据").Range("k" & m + 1 & ":k" & r) = "=""非营养餐"""
Sheets("配送数据").[f2] = "=VLOOKUP(E2,基础资料!$L$1:$N$132,2,0)"
Sheets("配送数据").Range("f" & m + 1 & ":f" & r).FillDown
Sheets("配送数据").[h2] = "=VLOOKUP(E2,基础资料!$L$1:$N$132,3,0)"
Sheets("配送数据").Range("h" & m + 1 & ":h" & r).FillDown
Sheets("配送数据").[j2] = "=VLOOKUP(D2,基础资料!$A$1:$I$70,9,0)"
Sheets("配送数据").Range("j" & m + 1 & ":j" & r).FillDown
For i = 2 To m
Sheets("配送数据").Cells(i, "I") = Sheets("配送数据").Cells(i, "G") * Sheets("配送数据").Cells(i, "H ")
Sheets("配送数据").Cells(i, 4).Resize(d.Count) = Sheets("就餐人数").Range("A" & i + 3)
Next
End With
d.RemoveAll
Next rr
Next r
Set d = Nothing
Sheets("配送数据").Select
End Sub
改进上述代码后,实现大部分功能,请大神在此基码上,再改进一下代码,实现我想实现在的全部功能,谢谢 |
|