我正在尝试实现以下目标:向用户显示一个 Excel 电子表格,其中包含他们可以更改的假设列表。
Title | Value |
Input01 | 10 | =
Input02 | 2 | >=
Input03 | 800 | >=
Input04 | 4 | >=
Input05 | 2 | <=
If .. Then如果满足假设,则有一个声明会提取数据。但是,如果假设是空白的,则不应将其包含在If .. Then声明中。
If x = Input01Value And y >= Input02Value _
And z >= Input03Value And a >= Input04Value _
And b <= Input05Value Then
用户省略 Input03
If x = Input01Value And y >= Input02Value _
And a >= Input04Value And b <= Input05Value Then
现在我可以检查每个值是否存在,然后在它后面加上另一个If带有适当变量的语句。但这似乎有点多余。
我想知道是否可能出现以下情况:
Input 01 = ""
If Input01Value != "" Then Input01 = "x = " & Input01Value
'Then use join or something similar to join all of them ..
然后Input01在If .. Then语句中直接使用这个。这样,当变量为空时,And ..不包括在内,并且If语句不会失败。
例如。(我知道这不起作用,只是说明场景)
VBA: If Input01 Then
Result while compiling: If x = Input01Value Then
请注意,我知道我可以执行以下操作:
If Boolean And Variable2 > 4 Then然后在单元格中拥有Boolean并Variable2填充一个值,但是这样做的问题是,例如,如果用户决定省略Variable2(这是合理的)它将失败。例如。If (Boolean = True) And > 4 Then.
希望我的问题很清楚,感谢您的帮助。