繁体   English   中英

VBA 有条件地为变量赋值

[英]VBA assign value to variable conditionally

是否可以在一行中有条件地为变量赋值?

Dim a as String
Dim b as String
a="hello world"

If a="hello world" Then b="Yes" Else b="No" 

是否可以在一行中使用类似于 SQL 语法的方式执行上述代码 - 如下所示:

b = Case When a="hello world" Then "Yes" Else "No" End

那就是 IIF 函数。

dim a as string
dim b as string
a ="hello world"
b = IIF(a="hello world", "Yes", "No")

格式遵循问题、真条件、假条件的基本三元格式。 该函数可以返回对象以及数据类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM