|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 测试12()
- Dim arr, brr
- Set d = CreateObject("Scripting.Dictionary")
- Set s = New Collection
- arr = Sheets(1).UsedRange
- brr = Sheets(2).UsedRange
- For i = 2 To UBound(brr)
- If brr(i, 1) = "主动方" Then s.Add i
- Next
- brr = Sheets(2).Cells(s(1), 1).CurrentRegion
- For i = 3 To UBound(brr)
- For u = 2 To UBound(brr, 2)
- If Not d.exists(brr(i, 1) & brr(2, u)) And IsNumeric(brr(i, u)) Then d(brr(i, 1) & brr(2, u)) = brr(i, u)
- Next
- Next
- For p = 2 To s.Count
- brr = Sheets(2).Cells(s(p), 1).CurrentRegion
- For i = 2 To UBound(brr)
- For u = 2 To UBound(brr, 2)
- If d.exists(brr(i, 1) & brr(1, u)) And IsNumeric(brr(i, u)) Then d(brr(i, 1) & brr(1, u)) = d(brr(i, 1) & brr(1, u)) + brr(i, u)
- If Not d.exists(brr(i, 1) & brr(1, u)) And IsNumeric(brr(i, u)) Then d(brr(i, 1) & brr(1, u)) = brr(i, u)
- Next
- Next
- Next
- For i = 3 To UBound(arr)
- For u = 3 To UBound(arr, 2)
- If d.exists(arr(i, 2) & arr(2, u)) Then arr(i, u) = d(arr(i, 2) & arr(2, u))
- Next
- Next
- Sheets(1).Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- Set d = Nothing
- Set s = Nothing
- Set arr = Nothing
- Set brr = Nothing
- End Sub
复制代码
|
|