Mã:
Public Function SumPower(TypeFunc As Byte, Source As Variant, ParamArray AllRange() As Variant) As Double
Dim Rng As Variant, Cell As Range, SumT As Double
Application.Volatile
With WorksheetFunction
Select Case TypeFunc
Case 1 'Cong các ô có hay không có chua Giá Tri Loi
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If -IsError(Cell) = Source Then SumT = .Sum(SumT, Cell)
Next
Next
GoTo Finish
Case 2 'Cong các ô có Giá Tri bang gia tri nguon "Source"
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If Val(Cell) = Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 3 'Cong các ô có Giá Tri nho hon gia tri nguon "Source"
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If Val(Cell) < Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 4 'Cong các ô có Giá Tri lon hon gia tri nguon "Source"
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If Val(Cell) > Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 5 'Cong các ô có hay không có chua Công Thuc
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If -Cell.HasFormula = Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 6 'Cong các ô có hay không có chua Font Chu In Dam
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If -Cell.Font.Bold = Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 7 'Cong các ô có hay không có chua Mau Font Chu
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If -(Cell.Font.ColorIndex > 0) = Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 8 'Cong các ô có chua Mau Font Chu tuong tu nhu ô goc "Source"
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If Cell.Font.ColorIndex = Source.Font.ColorIndex Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 9 'Cong các ô có hay không có chua Mau Nen
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If -(Cell.Interior.ColorIndex > 0) = Source Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
GoTo Finish
Case 10 'Cong các ô có chua Mau Nen tuong tu nhu ô goc "Source"
For Each Rng In AllRange()
For Each Cell In Union(Rng.SpecialCells(2, 19), Rng.SpecialCells(-4123, 19))
If Not IsError(Cell) Then
If Cell.Interior.ColorIndex = Source.Interior.ColorIndex Then
SumT = .Sum(SumT, Val(Cell))
End If
End If
Next
Next
End Select
End With
Finish: SumPower = SumT
End Function
-----------------------------------------------------------------------------------------
Bạn đang có kế hoạch du lịch Lào, khám phá “đất nước Triệu Voi"? Lưu lại ngay danh sách 13 địa điểm du lịch Lào cực nổi tiếng này để lên kế hoạch vi vu khám phá ngay trong chuyến đi sắp tới nhé! ...
Check in top 12 thắng cảnh tuyệt đẹp trong tour du lịch Lào