VBA学习07_While循环/DO WHILE 循环

For

当一天和尚,撞一天钟

While

我不会在任务没完成的情况下离开的

WHILE  循环条件
	循环体
WEND
WHILE Cells(i, 1) <> ""
    If Cells(i, 2) < 60 Then
        Cells(i, 2).Font.Color = vbRed
    End If
    
    i = i + 1
WEND	

DO While

Do While Cells(i, 1) <> ""
    If Cells(i, 2) < 60 Then
        Cells(i, 2).Font.Color = vbRed
    End If
    
    i = i + 1
Loop
Sub report()
	Dim i , total ,count 
	
	total  = 0
	count = 0
	
	i = 2
	Do	While  Cells(i,1) <> ""
		total  = tatal + Cells(i,2)    '总成绩
		count  = count + 1     '学生人数
		i = i + 1    '循环变量
	Loop
	
	If count > 0 Then
		Cells(4,4) = total / count
	End If
End Sub

嵌套循环

Sub changeUnit()
	Dim i ,j ,ws
	For Each ws In Worksheets ''--------> 一层循环
		i = 2
		' i 代表行号,遇到第一列为空的行则停止
		Do While ws.Cells(i,1) <> ""   '--------> 二层循环
			' j代表列号,每行都是9列
			For j = 2 To 10  			'--------> 三层循环
				ws.Cells(i,j) = ws.Cells (i,j) * 0.453
			Next j 
			i = i + 1
		Loop
		ws.Cells(i,9) = "磅"
	Next ws
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pigerr杨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值