![51736d4a62f10c69e3721a8260b35ef1.png](https://img-blog.csdnimg.cn/img_convert/51736d4a62f10c69e3721a8260b35ef1.png)
SunYoung
1、 If判断语句
语法:If 条件 Then 语句1
End If
例如:If Cells(1,1)>90 Then ‘判断A1单元格的值是否大于90,如果大于90
MsgBox”优秀”,vbinformation,”提示” ‘弹出信息提示框,显示优秀
End If
![c6d584832d4c7e2e15c320c70972e501.png](https://img-blog.csdnimg.cn/img_convert/c6d584832d4c7e2e15c320c70972e501.png)
优秀
语法:If 条件1 Then 语句1
Elseif 条件2 Then 语句2
End If
例如:If Cells(1,1)<60 Then ‘判断A1单元格的值是否小于60,如果小于60
MsgBox”不及格”,vbinformation,”提示” ‘弹出信息提示框,显示不及格
Elseif Cells(1,1)<90 Then ‘大于60而小于90
MsgBox”中等”,vbinformation,”提示” ‘弹出信息框,显示中等
Elseif Cells(1,1)<=100 Then ‘大于90
MsgBox”优秀”,vbinformation,”提示” ‘弹出信息框,显示优秀
End If
![f6e3c23bd594f5a8a3ee93eacf35d7a1.png](https://img-blog.csdnimg.cn/img_convert/f6e3c23bd594f5a8a3ee93eacf35d7a1.png)
小于60显示不及格
![dbb7ba599917db266d3fa54350f88473.png](https://img-blog.csdnimg.cn/img_convert/dbb7ba599917db266d3fa54350f88473.png)
中等
![e34da460b68c0ad69da417cdedd53466.png](https://img-blog.csdnimg.cn/img_convert/e34da460b68c0ad69da417cdedd53466.png)
优秀
2、 For…Next…循环语句
例如: For i=1 To 10 ‘功能是第一列显示1,2,3……10
Cells(i,1)=i ‘单元格的值随着i的值而改变
Next i
![93e0b7e1281875a9ab01f476acf9dd50.png](https://img-blog.csdnimg.cn/img_convert/93e0b7e1281875a9ab01f476acf9dd50.png)
填入数
例如:从E1~E23区域数据中找出与A1~A13区域中关键字相同的数据挑选出来,把与之对应F1~F23中的值复制到B1~B13
For i=1 To 13
For j=1 To 23
If Cells(i,1)=Cells(j,5) Then
Cells(i,2)=Cells(j,6) ‘也可以写成Cells(j,6).Copy Cells(i,2)
End If
Next j
Next i
![054dff88575af7825251c6361fc6953e.png](https://img-blog.csdnimg.cn/img_convert/054dff88575af7825251c6361fc6953e.png)
查找需要的数据
未完待续......