|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- p = 0
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:c" & r)
- For i = 2 To UBound(arr)
- If .Cells(i, 3).MergeArea.Cells(1, 1).Address = .Cells(i, 3).Address Then
- p = p + 1
- hs = .Cells(i, 3).MergeArea.Rows.Count
- For k = 1 To hs
- d(arr(i + k - 1, 1)) = Array(arr(i + k - 1, 2), arr(i, 3), p, hs)
- Next
- End If
- Next
- r = .Cells(.Rows.Count, 6).End(xlUp).Row
- arr = .Range("f2:f" & r)
- s = 0
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 1)) Then
- brr = d(arr(i, 1))
- s = s + brr(0)
- If brr(3) = 1 Then
- s = s + brr(1)
- Else
- If Not d1.exists(brr(2)) Then
- Set d1(brr(2)) = CreateObject("scripting.dictionary")
- End If
- d1(brr(2))(arr(i, 1)) = d1(brr(2))(arr(i, 1)) + 1
- End If
- End If
- Next
- For Each aa In d1.keys
- x = Application.Max(d1(aa).items)
- brr = d(d1(aa).keys()(0))
- s = s + x * brr(1)
- Next
- .Range("g2") = s
- End With
- End Sub
复制代码 |
|