|
Sub 提取数据()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Date, r As Long, rs As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
rr = Array(1, "星期一", 2, "星期二", 3, "星期三", 4, "星期四", 5, "星期五")
For i = 0 To UBound(rr) Step 2
d(rr(i)) = rr(i + 1)
Next i
With Sheets("带量食谱核算")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "带量食谱核算为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, 8))
End With
ReDim br(1 To UBound(ar), 1 To 6)
ReDim cr(1 To UBound(ar), 1 To 6)
With Sheets("日常餐物资出库表")
ks = .[b2]
js = .[d2]
For i = ks To js
xq = Application.Weekday(i, 2)
zc = d(xq)
For s = 2 To UBound(ar)
If Trim(ar(s, 1)) = zc Then
n = n + 1
br(n, 1) = i
br(n, 2) = ar(s, 2)
For j = 5 To 8
br(n, j - 2) = ar(s, j)
Next j
If ar(s, 5) = "牛奶" Or ar(s, 5) = "牛肉" Then
zd = i & "|" & ar(s, 2) & "|" & ar(s, 5)
t = dc(zd)
If t = "" Then
k = k + 1
dc(zd) = k
t = k
cr(k, 1) = i
cr(k, 2) = ar(s, 2)
cr(k, 3) = ar(s, 5)
cr(k, 5) = ar(s, 7)
End If
cr(t, 4) = cr(t, 4) + ar(s, 6)
cr(t, 6) = cr(t, 6) + ar(s, 8)
End If
End If
Next s
Next i
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(rs, 1).Resize(n, UBound(br, 2)) = br
End With
With Sheets("营养餐物资出库表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(rs, 1).Resize(k, UBound(cr, 2)) = cr
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|