|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
修正了数据统计的条件,“自查考评汇总”表中汇总后数据移位了,请教各位大神是哪一句未修正导致数据汇总格式未能对位汇总,谢谢!
Sub 去重统计()
Dim Arr, Brr(), i%, k%, j%
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
Arr = Sheet7.[A1].CurrentRegion '原始数据装入数组
ReDim Brr(1 To UBound(Arr), 1 To 9)
For i = 3 To UBound(Arr)
'If Not dic.exists(Arr(i, 2) & "|" & Arr(i, 7)) Then
If Not dic.exists(Arr(i, 7)) Then
k = k + 1
'dic(Arr(i, 2) & "|" & Arr(i, 7)) = k
dic(Arr(i, 7)) = k
Brr(k, 1) = k
'Brr(k, 2) = Arr(i, 2) '部门(即车站)
Brr(k, 3) = Arr(i, 7) '检查人
If Arr(i, 10) = "否" Then
Brr(k, 4) = 1 'J列否的合计--》自查问题
End If
If Arr(i, 9) = "是" Then
Brr(k, 5) = 1 'I列是的合计--》自查差错
End If
Brr(k, 7) = "2.06"
Brr(k, 9) = "张三"
Else
'j = dic(Arr(i, 2) & "|" & Arr(i, 7))
j = dic(Arr(i, 7))
If Arr(i, 10) = "否" Then
Brr(j, 4) = Brr(j, 4) + 1
End If
If Arr(i, 9) = "是" Then
Brr(j, 5) = Brr(j, 5) + 1
End If
End If
Next i
For i = LBound(Brr) To UBound(Brr)
If Len(Brr(i, 1)) > 0 Then
For j = 4 To 5
If Len(Brr(i, j)) = 0 Then Brr(i, j) = 0
Next j
Brr(i, 6) = "自查问题共" & Brr(i, 4) & "条,差错" & Brr(i, 5) & "条"
If Brr(i, 4) >= 20 Then
jf = 2
ElseIf Brr(i, 4) >= 15 Then
jf = 1.5
ElseIf Brr(i, 4) >= 10 Then
jf = 1
ElseIf Brr(i, 4) >= 5 Then
jf = 0.5
Else
jf = 0
End If
If Brr(i, 8) <= 2 Then
Brr(i, 8) = Val(jf) + Brr(i, 5) * 0.5
Else
Brr(i, 8) = 2
End If
If Brr(i, 8) > 2 Then Brr(i, 8) = 2
End If
Next i
'Stop
Sheets("自查考评汇总").Cells(3, 1).Resize(UBound(Brr), UBound(Brr, 2)) = Brr
End Sub
|
|