Board logo

標題: [分享] 總和最多季節 [打印本頁]

作者: hcm19522    時間: 2025-11-14 13:37     標題: 總和最多季節

[attach]38268[/attach]
作者: hcm19522    時間: 2025-11-14 13:38

(搜尋 輸入號碼 14540) google網址:https://hcm19522.blogspot.com/
作者: Andy2483    時間: 2025-11-19 16:31

回復 1# hcm19522


    謝謝前輩分享此主題,後學藉此帖練習陣列與字典,請各位前輩指教

執行前:
[attach]38287[/attach]

執行結果:
[attach]38288[/attach]

Option Explicit
Sub TEST()
Dim Brr, Z, i&, j%, M&, C%, N&, R&
Set Z = CreateObject("Scripting.Dictionary")
R = [A1].End(xlDown).Row
If R + 3 <= [A65536].End(3).Row Then
   Range(Cells(R + 3, "A"), [A65536].End(3)).EntireRow.Delete
End If
Brr = Range([M2], [A65536].End(3))
For i = 1 To UBound(Brr)
   M = 0
   For j = 0 To 3
      N = 0
      For C = 2 To 4
         N = N + Brr(i, j * 3 + C)
         Brr(i, j * 3 + C) = ""
      Next
      Brr(i, j * 3 + C - 3) = N
      If M < N Then
         Z(Brr(i, 1)) = j + 1
         M = N
      End If
   Next
Next
[O2].Resize(UBound(Brr), 1) = Application.Transpose(Z.Items)
Cells(R + 3, "A").Resize(UBound(Brr), 13) = Brr
End Sub




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)