|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 测试()
- Dim i%, j%, k%, m%, n%, arr, brr, crr, drr
- Dim dic As Object, key, keys, items
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet2.Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- key = arr(i, 12)
- If Not dic.Exists(key) Then
- ReDim brr(1 To 5)
- brr(1) = key
- If arr(i, 4) = "字段1" Then
- brr(2) = 1
- ElseIf arr(i, 4) = "字段2" Then
- brr(3) = 1
- ElseIf arr(i, 4) = "字段3" Then
- brr(4) = 1
- End If
- brr(5) = brr(2) + brr(3) + brr(4)
- dic(key) = brr
- Else
- brr = dic(key)
- If arr(i, 4) = "字段1" Then
- brr(2) = brr(2) + 1
- ElseIf arr(i, 4) = "字段2" Then
- brr(3) = brr(3) + 1
- ElseIf arr(i, 4) = "字段3" Then
- brr(4) = brr(4) + 1
- End If
- brr(5) = brr(2) + brr(3) + brr(4)
- dic(key) = brr
- End If
- Next
- keys = dic.keys
- Sheet1.Cells(2, 5).Resize(10000, 3).ClearContents
- For i = 2 To Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
- key = Sheet1.Cells(i, 2)
- brr = dic(key)
- For j = 2 To 5
- Sheet1.Cells(i, j + 3) = brr(j)
- Next
- Next
- End Sub
复制代码 |
|