【问题标题】:Unable to restrict input such that min < mode < max无法限制输入使得 min < mode < max
【发布时间】:2026-02-16 09:20:02
【问题描述】:

我正在尝试编写一个限制其输入的 VBA 函数。它需要三个参数minmodemax,并且需要确保min &lt; mode &lt; max

这是我目前所拥有的:

Function TRIANGULAR(min As Double, mode As Double, max As Double)
    If min < mode < max Then
        TRIANGULAR = (min + mode + max) / 3
    Else
        MsgBox "min < mode < max", vbCritical
    End If
End Function

我错过了什么?

【问题讨论】:

    标签: excel operators comparison-operators vba


    【解决方案1】:

    If 不是这样工作的。

    使用

    If (min < mode) and (mode < max) Then
    

    【讨论】:

    • 谢谢@Chris,我不知道 :) .... 我还有一个关于“数据透视表”的问题,我希望你也能帮助我 :)
    • @Rachit 如果 Chris 的回答已经回答了您的问题,您可以通过单击此答案旁边的复选标记来接受它。它有助于让其他人知道您的问题已经解决。 (Plus a bunch of other stuff)