|
本帖最后由 ykcbf1100 于 2024-1-28 11:38 编辑
参与一下,代码以附件为立准。- Sub ykcbf() '//2024.1.26
- Dim arr, brr, d
- Set d = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Set d3 = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- r = Me.Cells(Rows.Count, 1).End(3).Row
- Me.Range("a2:d" & r - 1).Sort Me.[a2], 1
- arr = Me.Range("a1:d" & r)
- jn = Year(Date)
- For i = 2 To UBound(arr)
- If arr(i, 3) = "STR" Then
- s = Left(CStr(arr(i, 1)), 4)
- d2(s) = ""
- s = arr(i, 2)
- p1 = IIf(Left(CStr(arr(i, 1)), 4) = CStr(jn), arr(i, 4), 0)
- p2 = p2 + IIf(Left(CStr(arr(i, 1)), 4) = CStr(jn), arr(i, 4), 0)
- p3 = p3 + arr(i, 4)
- If Not d.exists(s) Then
- d3(s) = Array(s, p1, p2, p3)
- Else
- t = d3(s)
- t(1) = t(1) + p1
- t(2) = t(2) + p2
- t(3) = t(3) + p3
- d3(s) = t
- End If
- s = arr(i, 2) & "|" & Left(CStr(arr(i, 1)), 4)
- d(s) = d(s) + arr(i, 4)
- End If
- Next
- Me.[l2:z10000] = ""
- Me.[p1:z1] = ""
- Me.[p1].Resize(1, d2.Count) = d2.keys
- Me.[l2].Resize(d3.Count, 4) = Application.Rept(d3.Items, 1)
- arr = Me.[l1].Resize(d3.Count + 1, d2.Count + 4)
- For i = 2 To UBound(arr)
- For j = 5 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(1, j)
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- Me.[l1].Resize(d3.Count + 1, d2.Count + 4) = arr
- Set d = Nothing
- Set d2 = Nothing
- Set d3 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|