2009年4月24日

EXCEL -VBA 自動加總

EXCEL -VBA 自動加總
這是解決學生要自動加總的VBA程式
Sub 自動加總()Dim r1, r2, c1, c2, ss = 0
r1 = ActiveCell.Rowc1 = ActiveCell.Column While (ActiveCell(r1, c1).Value <> Empty)
While (ActiveCell(r1, c1).Value <> Empty) s = s + ActiveCell(r1, c1).Value r1 = r1 + 1 Wend ActiveCell(r1, c1).Value = s r1 = ActiveCell.Row c1 = c1 + 1 s = 0 Wend r1 = ActiveCell.Rowc1 = ActiveCell.Column
While (ActiveCell(r1, c1).Value <> Empty)
While (ActiveCell(r1, c1).Value <> Empty) s = s + ActiveCell(r1, c1).Value c1 = c1 + 1 Wend ActiveCell(r1, c1).Value = s c1 = ActiveCell.Row r1 = r1 + 1 s = 0 Wend End Sub
http://alexsir.blogspot.com/2009/04/excel-vba_23.html

沒有留言:

張貼留言