Header ads

Header ads
» » Hàm Sum nhiều tính năng

Mình gửi đến các bạn vài hàm Sum tự tạo nhằm đa dạng hóa tính năng cộng của hàm Sum

Đầu tiên là hàm SumType :
Chức năng :
- Cộng các ô có chứa hay không chứa công thức.
- Cộng các ô có hay không có màu nền
- Cộng các ô có hay không có màu Font chữ
- Cộng các ô có hay không có Font chữ in đậm
- Bỏ qua các ô bị lỗi khi cộng
Link hàm: Sum.xls
Code:
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 DoubleFor Each Cell In Rng1If 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 
IfEnd IfNext'---------------------------------------------------------------------'If Not Rng2 Is Nothing ThenFor Each Cell In Rng2If 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 
IfEnd IfNext
End 
If'---------------------------------------------------------------------'If Not Rng3 Is Nothing ThenFor Each Cell In Rng3If 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 
IfEnd IfNext
End 
If'---------------------------------------------------------------------.'If Not Rng4 Is Nothing ThenFor Each Cell In Rng4If 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 
IfEnd IfNext
End 
If'---------------------------------------------------------------------.'If Not Rng5 Is Nothing ThenFor Each Cell In Rng5If 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 
IfEnd IfNext
End 
IfSumType = SumT
End 
Function 

About Học viện đào tạo trực tuyến

Xinh chào bạn. Tôi là Đinh Anh Tuấn - Thạc sĩ CNTT. Email: dinhanhtuan68@gmail.com .
- Nhận đào tạo trực tuyến lập trình dành cho nhà quản lý, kế toán bằng Foxpro, Access 2010, Excel, Macro Excel, Macro Word, chứng chỉ MOS cao cấp, IC3, tiếng anh, phần mềm, phần cứng .
- Nhận thiết kế phần mềm quản lý, Web, Web ứng dụng, quản lý, bán hàng,... Nhận Thiết kế bài giảng điện tử, số hóa tài liệu...
HỌC VIỆN ĐÀO TẠO TRỰC TUYẾN:TẬN TÂM-CHẤT LƯỢNG.
«
Next
Bài đăng Mới hơn
»
Previous
Bài đăng Cũ hơn