excel VBA判断语句
时间:2023-10-05 08:11:48
本文教你如何使用VBA判断语句。
1)If…Then…Else语句
If condition Then [statements][Else elsestatements]
如1:If A>B And C<D Then A=B+2 Else A=C+2
如2:If x>250 Then x=x-100
或者,可以使用块形式的语法:
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] …
[Else
[elsestatements]]
End If
如1:
If Number < 10 Then
Digits = 1
ElseIf Number < 100 Then
Digits = 2
Else
Digits = 3
End If
2)Select Case…Case…End Case语句
如1:
Select Case Pid
Case “A101”
Price=200
Case “A102”
Price=300
……
Case Else
Price=900
End Case
3)Choose 函数
choose(index, choce-1,choice-2,…,choice-n),可以用来选择自变量串列中的一个值,并将其返回,index 必要参数,数值表达式或字段,它的运算结果是一个数值,且界于 1 和可选择的项目数之间。choice 必要参数,Variant表达式,包含可选择项目的其中之一。如:
GetChoice = Choose(Ind, "Speedy", "United", "Federal")
4)Switch函数
Switch(expr-1, value-1[, expr-2, value-2 _ [, expr-n,value-n]])
switch函数和Choose函数类似,但它是以两个一组的方式返回所要的值,在串列中,最先为TRUE的值会被返回。 expr 必要参数,要加以计算的 Variant 表达式。value 必要参数。如果相关的表达式为 True,则返回此部分的数值或表达式,没有一个表达式为 True,Switch 会返回一个 Null值。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
初页app如何设置自动播放 初页APP设置自动播放的图文教程
![](https://img.aspxhome.com/file/2023/8/a335180_0s.png)
excel表格的sum公式的教程
Win10 Build 10162和10166的ISO镜像下载和在线升级今日关闭
![](https://img.aspxhome.com/file/2023/28/a249129_0s.jpg)
Excel LOGINV 函数 使用实例教程
![](https://img.aspxhome.com/file/2023/7/a162317_0s.png)
Pixelmator Pro与pixelmator相比有哪些具体区别?
![](https://img.aspxhome.com/file/2023/3/a213703_0s.jpeg)
wps表格中如何插入复选框?
暴雪战网怎么改名字?暴雪战网改名字的方法
![](https://img.aspxhome.com/file/2023/7/a327420_0s.jpg)
怎样设置wps页码
电脑版wps文档的页脚图片如何添加边框
![](https://img.aspxhome.com/file/2023/4/a183134_0s.png)
腾讯视频怎么投屏到电视-腾讯视频投屏到电视教程
![](https://img.aspxhome.com/file/2023/3/a298929_0s.jpg)
怎么装系统windows10?安装windows10系统的方法
![](https://img.aspxhome.com/file/2023/2/47692_0s.jpg)
Macbook如何连接电视?Mac电脑连接AppleTV小技巧
![](https://img.aspxhome.com/file/2023/5/a203885_0s.jpeg)
Mac如何更改文件的默认打开方式
![](https://img.aspxhome.com/file/2023/6/a204006_0s.png)
win7打印机共享错误0x000003e3错误怎么设置?
![](https://img.aspxhome.com/file/2023/30/a263710_0s.jpg)
西瓜影音怎么样?西瓜影音好用吗?
![](https://img.aspxhome.com/file/2023/9/a340701_0s.jpg)
一个链接就让Mac死机 亲身测试有效
![](https://img.aspxhome.com/file/2023/9/a214729_0s.png)
如何破坏Word文件
![](https://img.aspxhome.com/file/2023/8/23848_0s.jpg)
两周没更新了,iOS12.1.1 beta4哪天会来?
Win10电脑C盘用户文件夹里的东西可以删除吗?
![](https://img.aspxhome.com/file/2023/0/52290_0s.png)
Win7系统开始菜单中的运行命令不见了怎么办呢?
![](https://img.aspxhome.com/file/2023/5/a313651_0s.jpg)