Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created December 22, 2016 09:40
Show Gist options
  • Select an option

  • Save ndthanh/da9e458d8e47eb84bdbcf1c78f2bb432 to your computer and use it in GitHub Desktop.

Select an option

Save ndthanh/da9e458d8e47eb84bdbcf1c78f2bb432 to your computer and use it in GitHub Desktop.
Function SumByColor(CellColor As Range, rRange As Range)
'Thêm dòng này để công thức tự update với Excel 2010 trở lên
' Với Excel 2007, có thể dùng CTRL + ALT + F9
Application.Volatile True
Dim cSum As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each cl In rRange
If cl.Interior.ColorIndex = ColIndex Then
cSum = WorksheetFunction.SUM(cl, cSum)
'~~> cSum = cSum + cl
End If
Next cl
SumByColor = cSum
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment