Cộng các ô cùng màu

  • Thread starter tuanh
  • Ngày gửi
T

tuanh

Guest
22/1/06
21
0
1
46
HN
Em muốn cộng các ô cùng màu lại với nhau. ANh chi chỉ giùm em nhé. thank:pepsi:
 
Khóa học Quản trị dòng tiền
S

SA_DQ

Thành viên Cố vấn - Webketoan Mentors
29/6/05
626
104
43
68
HCM city
Đây là ví dụ tô màu nền bất kỳ & cộng


Sub ColorRange()

Dim iColor As Integer, iSum As Long
Dim Rng As Range, Rng0 As Range
Randomize
iColor = 34 + Int(6 * Rnd)
Set Rng = Range("B1:C16")
For Each Rng0 In Rng
With Rng0
If .Value Mod 4 < 2 Then
.Interior.ColorIndex = iColor
.Interior.Pattern = xlSolid
iSum = iSum + .Value
End If
End With
Next Rng0
Set Rng = Nothing
Range("B18").Value = "Sum Of Color Ranges:" & "(" & CStr(iColor) & ")."
Range("c19").Value = iSum
End Sub
Bạn sẽ rõ hơn khi xem cái này:
Sub SumColorRanges()
Dim iColor As Integer
ReDim iSum(34 To 40) As Long
Dim Rng As Range, Rng0 As Range

Set Rng = Range("B1:C16"): Application.ScreenUpdating = False
For Each Rng0 In Rng
With Rng0
Randomize: iColor = 34 + Int(6 * Rnd)
.Interior.ColorIndex = iColor
.Interior.Pattern = xlSolid
iSum(iColor) = iSum(iColor) + .Value
End With
Next Rng0
Set Rng = Range("A19"): Set Rng0 = Range("A18")
For iColor = 0 To 6
Rng.Offset(, iColor).Value = iSum(iColor + 34)
Rng0.Offset(, iColor).Interior.ColorIndex = iColor + 34
Rng0.Offset(, iColor).Value = iColor + 34
Next iColor
Set Rng = Nothing: Set Rng0 = Nothing
Application.ScreenUpdating = True
End Sub
 
Sửa lần cuối:

Xem nhiều