Public Function SumType(TypeFunc As Byte, Opt As Boolean, Rng1 As Range, Optional Rng2 As Range, Optional Rng3 As Range, Optional Rng4 As Range, Optional Rng5 As Range) As Double
Dim Cell As Range, SumT As Double
For Each Cell In Rng1
If Not IsError(Cell) Then
If IsNumeric(Cell) Then
Select Case TypeFunc
Case 1 'cong cac cell dang value hay formula
If Cell.HasFormula = Opt Then SumT = SumT + Cell
Case 2 'cong cac cell co mau hay khong co mau nen
If Cell.Interior.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 3 'cong cac cell co mau hay khong co mau font chu
If Cell.Font.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 4 'cong cac cell co hay khong co font in dam
If Cell.Font.Bold = Opt Then SumT = SumT + Cell
End Select
End If
End If
Next
'---------------------------------------------------------------------
If Not Rng2 Is Nothing Then
For Each Cell In Rng2
If Not IsError(Cell) Then
If IsNumeric(Cell) Then
Select Case TypeFunc
Case 1 'cong cac cell dang value hay formula
If Cell.HasFormula = Opt Then SumT = SumT + Cell
Case 2 'cong cac cell co mau hay khong co mau nen
If Cell.Interior.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 3 'cong cac cell co mau hay khong co mau font chu
If Cell.Font.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 4 'cong cac cell co hay khong co font in dam
If Cell.Font.Bold = Opt Then SumT = SumT + Cell
End Select
End If
End If
Next
End If
'---------------------------------------------------------------------
If Not Rng3 Is Nothing Then
For Each Cell In Rng3
If Not IsError(Cell) Then
If IsNumeric(Cell) Then
Select Case TypeFunc
Case 1 'cong cac cell dang value hay formula
If Cell.HasFormula = Opt Then SumT = SumT + Cell
Case 2 'cong cac cell co mau hay khong co mau nen
If Cell.Interior.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 3 'cong cac cell co mau hay khong co mau font chu
If Cell.Font.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 4 'cong cac cell co hay khong co font in dam
If Cell.Font.Bold = Opt Then SumT = SumT + Cell
End Select
End If
End If
Next
End If
'---------------------------------------------------------------------
If Not Rng4 Is Nothing Then
For Each Cell In Rng4
If Not IsError(Cell) Then
If IsNumeric(Cell) Then
Select Case TypeFunc
Case 1 'cong cac cell dang value hay formula
If Cell.HasFormula = Opt Then SumT = SumT + Cell
Case 2 'cong cac cell co mau hay khong co mau nen
If Cell.Interior.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 3 'cong cac cell co mau hay khong co mau font chu
If Cell.Font.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 4 'cong cac cell co hay khong co font in dam
If Cell.Font.Bold = Opt Then SumT = SumT + Cell
End Select
End If
End If
Next
End If
'---------------------------------------------------------------------
If Not Rng5 Is Nothing Then
For Each Cell In Rng5
If Not IsError(Cell) Then
If IsNumeric(Cell) Then
Select Case TypeFunc
Case 1 'cong cac cell dang value hay formula
If Cell.HasFormula = Opt Then SumT = SumT + Cell
Case 2 'cong cac cell co mau hay khong co mau nen
If Cell.Interior.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 3 'cong cac cell co mau hay khong co mau font chu
If Cell.Font.ColorIndex > 0 = Opt Then SumT = SumT + Cell
Case 4 'cong cac cell co hay khong co font in dam
If Cell.Font.Bold = Opt Then SumT = SumT + Cell
End Select
End If
End If
Next
End If
SumType = SumT
End Function