
统计所有学生的平均成绩,当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

公斤和磅之间转换(把所有的单元格kg单位转成磅单位,1kg~2.20磅)
sub 单位转换()
dim i , j as integer
for i =2 to 10
for j = 2 to 6
cells(j,i)=cells(j,i)*2.20
next
next
end sub
如果需要添加产品也会自动计算,可使用双循环:
sub 单位转换()
dim i,j as integer
i=2
do while cells(i,1)<>""
for j = 2 to 10
cells(i,j)=cells(i,j)*2.20
next
loop
end sub
转载于:https://blog.51cto.com/11729955/2325322
最后
以上就是虚拟黑夜最近收集整理的关于vba练习-while循环的全部内容,更多相关vba练习-while循环内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复