代码如下。。。
Sub test()
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("来料检验明细表")
Set sh = wb.Sheets("查询表")
r = sh.Cells(Rows.Count, 1).End(3).Row - 5
xm = sh.[d1]: d = sh.[f1]
s = xm & "|" & d
arr = sht.[a1].CurrentRegion
ReDim brr(1 To 10000, 1 To 100)
Set d = CreateObject("scripting.dictionary")
' n = 0: m = 3
' brr(1, 1) = "供应商名称": brr(1, 2) = "交付总数": brr(1, 3) = "不合格数"
biaoti = sh.[a3:o3]
For i = 4 To 12
d(biaoti(1, i)) = i
Next
For i = 2 To UBound(arr)
ss = arr(i, 3) & "|" & Month(arr(i, 7))
If InStr(ss, s) Then
hang = hang + 1
zong = zong + arr(i, 6)
If Not d.exists(arr(i, 13)) Then
n = n + 1
d(arr(i, 13)) = n
brr(n, 1) = arr(i, 13)
End If
If arr(i, 11) <> Empty Then
If d.exists(arr(i, 11)) Then
' m = m + 1
' d(arr(i, 11)) = m
' brr(1, m) = arr(i, 11)
y = d(arr(i, 11))
End If
End If
x = d(arr(i, 13))
' y = d(arr(i, 11))
brr(x, 100) = brr(x, 100) + 1
brr(x, 2) = brr(x, 2) + arr(i, 6)
brr(x, 3) = brr(x, 3) + arr(i, 9)
If y <> Empty Then brr(x, y) = brr(x, y) + arr(i, 9): y = Empty: brr(x, 99) = brr(x, 99) + 1
End If
Next
For i = 1 To n
brr(i, 13) = Format(1 - brr(i, 3) / brr(i, 2), "0.00%")
brr(i, 14) = Format(1 - brr(i, 99) / brr(i, 100), "0.00%")
brr(i, 15) = "=VLOOKUP(" & brr(i, 13) & ",{0,""E级"";0.8,""D级"";0.85,""C级"";0.9,""B级"";0.95,""A级""},2)"
Next
If n <= r Then
sh.[a4].Resize(r, UBound(biaoti, 2)) = ""
sh.[a4].Resize(n, UBound(biaoti, 2)) = brr
Else
sh.Cells(r + 4, 1).Resize(n - r).Insert xlShiftDown
sh.[a4].Resize(r, UBound(biaoti, 2)) = ""
sh.[a4].Resize(n, UBound(biaoti, 2)) = brr
End If
sh.[h1] = hang: sh.[j1] = zong
Set d = Nothing
Beep
End Sub
|