- VBA 教程
- VBA - 主页
- VBA - 概述
- VBA - Excel 宏
- VBA - Excel 术语
- VBA - 宏注释
- VBA - 消息框
- VBA - 输入框
- VBA - 变量
- VBA - 常量
- VBA - 运算符
- VBA - 决策
- VBA - 循环
- VBA - 字符串
- VBA - 日期和时间
- VBA - 数组
- VBA - 函数
- VBA - 子过程
- VBA - 事件
- VBA - 错误处理
- VBA - Excel 对象
- VBA - 文本文件
- VBA - 编程图表
- VBA - 用户窗体
- VBA 实用资源
- VBA - 快速指南
- VBA - 实用资源
- VBA - 讨论
VBA - If-Else 语句
If 语句由布尔表达式及一个或多个语句组成。如果条件为 True,则执行 If 条件下的语句。如果条件为 False,则执行 Else 部分下的语句。
语法
以下是 VBScript 中 If Else 语句的语法。
If(boolean_expression) Then Statement 1 ..... ..... Statement n Else Statement 1 ..... .... Statement n End If
流程图
示例
为了演示的目的,让我们借助一个函数找出 Excel 中两个数字中的较大的数字。
Private Sub if_demo_Click()
Dim x As Integer
Dim y As Integer
x = 234
y = 324
If x > y Then
MsgBox "X is Greater than Y"
Else
Msgbox "Y is Greater than X"
End If
End Sub
执行上述代码后,将生成以下结果。
Y is Greater than X
vba_decisions.htm
广告
