VBA如果<这些中的任何一个> =< value&gt ;? [英] VBA If <any of these> = <value>?

查看:257
本文介绍了VBA如果<这些中的任何一个> =< value&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手,我找不到一种简单的方法来测试任何指定的变量是否等于指定的值。以下似乎有效,但有更简单的方法吗?

I'm fairly new to VBA, and I can't find an easy way to test if any of the specified variables equal a specified value. The below seems to work, but is there an easier way to do it?

If variable1 = 1 Or variable2 = 1 Or variable3 = 1 Or variable4 = 1 Or variable5 = 1 Then End If

我也尝试过以下方法,没有运气。

I've also tried the following, with no luck.

If (variable1 Or variable2 Or variable3 Or variable4 Or variable5) = 1 Then End If


推荐答案

您可以使用选择案例:)

You can use select case :)

Sub Sample()
    Dim variable1, variable2, variable3, variable4, variable5

    variable1 = 1: variable2 = 1: variable3 = 1: variable4 = 1: variable5 = 1

    Select Case 1
        Case variable1, variable2, variable3, variable4, variable5
            MsgBox "One of them is equal to 1"
        Case Else
            MsgBox "none of then is equal to 1"
    End Select
End Sub

这篇关于VBA如果<这些中的任何一个> =< value&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆