Sub toRMB()Dim rate, i
If Cells(7,6)="USD"Then'做一个简单的if判断
rate = Cells(8,6)For i =11To20Step1'步长为1可省略,若是20 to 11,则step -1
Cells(i,6)= Cells(i,6)* rate
Next i '保持良好的代码风格,利用tab键缩进
Cells(7,6)="RMB"EndIfEndSub
Option Explicit
Sub 做加法()Dim i AsIntegerFor i =2To28Step1
Cells(i,6)= Cells(i,2)+ Cells(i,4)Next i
EndSub
if语句
Option Explicit
Sub calculate()Dim score
Dim i AsInteger
score =0For i =4To6Step1
score = Cells(i,6)+ score '简单求和Next i
score = score /3
Cells(7,6)= score 'if-elseif判断,elseif是一个整体If score >=90Then
Cells(8,6)="A"ElseIf score >=80Then'then不能忘掉
Cells(8,6)="B"ElseIf score >=70Then
Cells(8,6)="C"ElseIf score >=60Then
Cells(8,6)="D"Else
Cells(8,6)="Fail"EndIf'endif 不能少EndSub