2011年9月8日 星期四

VBA 下的 sumif 公式

    For j = 11 To 23
            Set rgc = Range(Cells(15, 5), Cells(15, 5).End(xlDown))
            Set rgf = Range(Cells(15, j), Cells(15, j).End(xlDown))
            Cells(10, j).Select
                       
            'ActiveCell.Formula = "=SUMIF(" & rgc.Address & ",""第一分類""," & rgf.Address & ")"
            Cells(10, j).Formula = "=SUMIF(" & rgc.Address & ",""第一分類""," & rgf.Address & ")"
            Cells(10, j) = Cells(10, j).Value
            Cells(11, j).Formula = "=SUMIF(" & rgc.Address & ",""第二分類""," & rgf.Address & ")"
            Cells(11, j) = Cells(11, j).Value
            Cells(12, j).Formula = "=SUMIF(" & rgc.Address & ",""第三分類""," & rgf.Address & ")"
            Cells(12, j) = Cells(12, j).Value
           
            Cells(8, j) = Cells(10, j).Value + Cells(11, j).Value + Cells(12, j).Value
           
    Next j

沒有留言: