Option Explicit
Sub E欄同底色合計_1()
Application.EnableEvents = False
Dim i&, C3&, C17&, T, C&
T = Timer
For i = 1 To Cells(Rows.Count, "E").End(3).Row
C = Cells(i, "E").Interior.ColorIndex
If C = 3 Then C3 = C3 + Val(Cells(i, "E"))
If C = 17 Then C17 = C17 + Val(Cells(i, "E"))
Next
[B1] = C3: [A1].Interior.ColorIndex = 3
[B2] = C17: [A2].Interior.ColorIndex = 17
Application.EnableEvents = True
MsgBox Format(Timer - T, "0.00秒")
End Sub
Sub E欄同底色合計_2()
Application.EnableEvents = False
Dim i&, C&, Y, Arr, T
T = Timer
Set Y = CreateObject("Scripting.Dictionary")
Arr = Range([E1], Cells(Rows.Count, "E").End(3))
For i = 1 To UBound(Arr)
C = Cells(i, "E").Interior.ColorIndex
Y(C) = Y(C) + Val(Arr(i, 1))
Next
[B1] = Y(3): [A1].Interior.ColorIndex = 3
[B2] = Y(17): [A2].Interior.ColorIndex = 17
Application.EnableEvents = True
MsgBox Format(Timer - T, "0.00秒")
End Sub
Sub 亂數重設()
Dim xArea, xR, R
Set xArea = [E1:E10000]
With xArea
.Value = "=INT(RAND()*100)"
.Value = .Value
.Interior.ColorIndex = 17
End With
For Each xR In xArea
If Int(Rnd() * 100) Mod 2 Then xR.Interior.ColorIndex = 3
Next
[B1:B2] = ""
End Sub