1. 程式人生 > >vba練習-while迴圈

vba練習-while迴圈

vba練習-while迴圈
統計所有學生的平均成績,當A列繼續輸入時,仍能統計。
Sub 統計()
Dim i, total, count
total = 0
count = 0
i = 2
Do While Cells(i, 1) <> ""
total = total + Cells(i, 2)
count = count + 1
i = i + 1
Loop
If count > 0 Then
Cells(3, 3).Value = total / count
End If
End Sub