- Sub 非重复汇总()
- Dim dic As Object
- Dim arr, m&, brr, crr()
- Set dic = CreateObject("Scripting.Dictionary")
- arr = Range("A1").CurrentRegion
- brr = Range("E1:H1")
- For m = 2 To UBound(arr, 1)
- If IsNumeric(arr(m, 3)) Then
- If arr(m, 3) >= brr(1, 2) And arr(m, 3) <= brr(1, 4) Then
- If Not dic.Exists(arr(m, 1)) Then
- Set dic(arr(m, 1)) = CreateObject("Scripting.Dictionary")
- End If
- dic(arr(m, 1))(arr(m, 2)) = ""
- End If
- End If
- Next
- ReDim crr(1 To dic.Count + 2, 1 To 2)
- crr(1, 1) = "城市": crr(1, 2) = "在岗人数": crr(dic.Count + 2, 1) = "总计"
- For m = 2 To UBound(crr, 1) - 1
- crr(m, 1) = dic.keys()(m - 2)
- crr(m, 2) = dic(dic.keys()(m - 2)).Count
- crr(dic.Count + 2, 2) = crr(dic.Count + 2, 2) + crr(m, 2)
- Next
- Range("E2:F2000").ClearContents
- Range("E2").Resize(UBound(crr, 1), 2) = crr
- End Sub
复制代码 |