Có thể cộng các ô theo mầu trong excel được không?

  • Thread starter Katherine
  • Ngày gửi
Khóa học Quản trị dòng tiền
levanduyet

levanduyet

Welcome
16/10/04
537
19
18
HCM
my.opera.com
Dĩ nhiên là có

Function SumByColor(InputRange As Range, ColorRange As Range) As Double
' trả về tổng của các ô trong InputRange Có màu giống màu nền
' của ô trong ColorRange
' ví dụ: =SumByColor($A$1:$A$20,B1)
' range A1:A20 là range bạn muốn tổng
' range B1 is ô với màu bạn muốn cộng
Dim cl As Range, TempSum As Double, ColorIndex As Integer
' Application.Volatile ' this is optional
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempSum = 0
On Error Resume Next ' ignore cells without values
For Each cl In InputRange.Cells
If cl.Interior.ColorIndex = ColorIndex Then
TempSum = TempSum + cl.Value
End If
Next cl
On Error GoTo 0
Set cl = Nothing
SumByColor = TempSum
End Function

Lê Văn Duyệt
Từ http://www.exceltip.com/st/Sum_by_color_using_VBA_in_Microsoft_Excel/517.html
 

Xem nhiều