全民一起VBA基础篇第四课:基本流程控制语句

for语句

Sub toRMB()
    Dim rate, i    
    If Cells(7, 6) = "USD" Then         '做一个简单的if判断    
        rate = Cells(8, 6)     
        For i = 11 To 20 Step 1         '步长为1可省略,若是20 to 11,则step -1
            Cells(i, 6) = Cells(i, 6) * rate
        Next i                          '保持良好的代码风格,利用tab键缩进        
        Cells(7, 6) = "RMB"     
    End If
End Sub

在这里插入图片描述

Option Explicit
Sub 做加法()
Dim i As Integer
    For i = 2 To 28 Step 1
        Cells(i, 6) = Cells(i, 2) + Cells(i, 4)
    Next i
End Sub

在这里插入图片描述

if语句

Option Explicit
Sub calculate()
	Dim score
	Dim i As Integer
	
	score = 0
	
	For i = 4 To 6 Step 1
	    score = Cells(i, 6) + score         '简单求和
	Next i
	
	score = score / 3
	Cells(7, 6) = score                     'if-elseif判断,elseif是一个整体
	If score >= 90 Then
	    Cells(8, 6) = "A"
	ElseIf score >= 80 Then                 'then不能忘掉
	    Cells(8, 6) = "B"
	ElseIf score >= 70 Then
	    Cells(8, 6) = "C"
	ElseIf score >= 60 Then
	    Cells(8, 6) = "D"
	Else
	    Cells(8, 6) = "Fail"
	End If                                  'endif 不能少

End Sub

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值