|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'这不是最近3个月的吧
Option Explicit
Sub test()
Dim i, j, dic, arr, key, n, t
Set dic = CreateObject("scripting.dictionary")
arr = Sheets("sheet1").[a1].CurrentRegion
Sheets("sheet2").Activate
For i = 2 To UBound(arr, 1)
If arr(i, 1) = [e2].Value Then
For j = 3 To 3 + [e5].Value - 1
dic(arr(i, 1) & "|" & arr(i, 2)) = dic(arr(i, 1) & "|" & arr(i, 2)) + arr(i, j)
Next
End If
Next
ReDim arr(1 To dic.Count, 1 To 3)
For Each key In dic.keys
n = n + 1: t = Split(key, "|")
arr(n, 1) = t(0): arr(n, 2) = t(1): arr(n, 3) = dic(key) / [e5].Value
Next
[a9].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub |
评分
-
1
查看全部评分
-
|