vba - 使用多个大小写是 <>

标签 vba excel

大家早上好,下午好:

我在 VBA 中有这样的声明:

Select Case MAAX(Fila, 1)
    Case Is <> 5, Is <> 10, Is <> 15, Is <> 20, Is <> 25, Is <> 30, Is <> 35, Is <> 40
            Do whatever
End Select

但它不起作用..有什么问题?

最佳答案

如果“不工作”是指您的 CASE 后面的语句总是被执行,您可能误解了该语句的工作原理:

If testexpression matches ANY Case expressionlist expression, the statements following that Case clause are executed ...



几乎不管 MAAX(Fila, 1) 里有什么,它肯定会至少匹配您的一个子句。

您需要重写您的 CASE 语句(或使用其他东西),以测试您真正想要的逻辑。

如果你真正想要的是你的测试值不是那些(5、10、...)中的任何一个,你可以做类似的事情
if v<>5 and v<>10 and v<>15 ...

或者,可能
 select case v mod 5
     case is <>0  'then it is not one of those in your list, 
                  'but it could be greater than 40, so you might have to test for that

关于vba - 使用多个大小写是 <>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48840726/

相关文章:

mySQL + vba,检查表中是否已存在某个项目

excel - 如何在 Excel 中使用 VBA 获取当前行并访问列?

C++ 输出到 .CSV 文件

vba - 通过查找函数进行字数统计返回的结果与宏不同

vba - 将变量传递给 Left(string, VariableHere) 不起作用

vba - 运行时错误 '13' : type mismatch VBA 2010 to ensure uppercase text in cell

vba - 从图表中删除空系列(使用 VBA)

Excel 2010 比较多列(2 列与其他 2 列)

vba - 一个单元格更新后自动用数据填充一列

vba - VBA 中 CommandButton 的 .caption 和 .text 属性有什么区别?