返回列表 上一主題 發帖

[發問] 將儲存格的黃底上的數字加總

回復 1# peter95
VBA 程式碼
  1. Option Explicit
  2. Sub Ex()
  3.     Dim D As Object, E As Variant, i As Integer
  4.     Set D = CreateObject("SCRIPTING.DICTIONARY")  '字典物件
  5.     With ActiveSheet.Range("A1:G53")
  6.         For Each E In .Cells
  7.             If D.EXISTS(E.Interior.ColorIndex) Then
  8.                     Set D(E.Interior.ColorIndex) = Union(D(E.Interior.ColorIndex), E)
  9.             Else
  10.                Set D(E.Interior.ColorIndex) = E
  11.             End If
  12.         Next
  13.         i = 1
  14.         For Each E In D.keys
  15.             With .Cells(i, .Columns.Count + 1).Resize(, 2)
  16.                 .Interior.ColorIndex = E
  17.                 .Value = Array("共計 " & Application.Sum(D(E)), "出現 " & D(E).Count & "次")
  18.             End With
  19.             i = i + 1
  20.         Next
  21.     End With
  22. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 生氣,就是拿別人的過錯來懲罰自己。
返回列表 上一主題