|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 统计()
Dim ar As Variant
Dim i As Long, rs As Long
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Dim rn As Range
Dim cr()
With Sheets("带量食谱")
rs = .Cells(Rows.Count, 3).End(xlUp).Row
If rs < 3 Then MsgBox "带量食谱为空,请先导入数据!": End
ar = .Range("a2:r" & rs)
End With
For i = 2 To UBound(ar)
If ar(i, 2) <> "" Then
zf = ar(i, 2)
d(zf) = i
End If
Next i
With Sheets("营养成分分析")
Set rn = .Columns(1).Find("营养成分", , , , , , 1)
If rn Is Nothing Then MsgBox "营养成分分析Al列没有【营养成分】字段!": End
ks = rn.Row
br = .Range("a1:s" & ks - 2)
ws = .Cells(Rows.Count, 1).End(xlUp).Row
If ws >= 33 Then .Range("a33:s" & ws) = Empty
ReDim cr(1 To UBound(br, 2), 1 To 19)
For j = 5 To 17 Step 3
For i = 4 To UBound(br)
If br(i, j) <> "" Then
xh = d(br(i, j))
If xh <> "" Then
For s = 5 To UBound(ar, 2)
T = dc(ar(1, s))
If T = "" Then
k = k + 1
dc(ar(1, s)) = k
T = k
rr = Split(ar(1, s), "(")
cr(k, 1) = rr(0)
cr(k, 2) = Replace(rr(1), ")", "")
End If
cr(T, j) = cr(T, j) + Val(ar(xh, s))
Next s
End If
End If
Next i
Next j
.Cells(ks + 1, 1).Resize(k, UBound(cr, 2)) = cr
End With
MsgBox "ok!"
End Sub
|
|