|
Sub 数组汇总() '求平均分
arr = [b2:b9]
For Each num In arr
n = n + 1
lj = lj + num
Next
MsgBox "平均分为:" & lj / n
End Sub
Sub 动态区域数组汇总() '求平均分
arr = Range([b2], Cells(Rows.Count, 2).End(xlUp))
For Each num In arr
n = n + 1
lj = lj + num
Next
MsgBox "平均分为:" & lj / n
End Sub
Sub 有条件的汇总() '大于等于80的平均分
arr = Range([b2], Cells(Rows.Count, 2).End(xlUp))
For Each num In arr
If num >= 80 Then
n = n + 1
lj = lj + num
End If
Next
MsgBox "平均分为:" & lj / n
End Sub
'结论:如果对数组中元素进行循环,是从上到下,从左到右 |
|