VBA 如何确保在 InputBox 中输入的数字小于在 InputBox 中输入的另一个数字?

How to make sure a number entered in an InputBox is less than another number entered in an InputBox in VBA?

我让用户输入我用来过滤行的下限和上限。例如,如果他们为下限键入 4,为上限键入 8,那么我将使用这些数字来过滤第一个单元格中包含 4、5、6、7 或 8 的行。

我的代码(我将在下面显示)确保用户只能输入一个数字(通过将类型指定为 1),但我想确保他们输入的第二个数字始终大于第一个.不确定我目前使用两个不同输入框的方式是否可行,但我不确定还能怎么做,因为这只是我在 VBA 中的第 4 天编码。我还想确保他们为下限和上限输入的数字都大于 0。

这是我的输入框代码:

LowerBound = Application.InputBox("Please enter the number of the first line item:", "First Line Item Number", , , , , , 1)
UpperBound = Application.InputBox("Please enter the number of the last line item:", "Last Line Item Number", , , , , , 1)

感谢任何帮助!

这将重复问题,直到输入两个有效值:

Sub LimitCheck()
    Dim Repeat As Boolean
    Repeat = True
    While Repeat
        lowerbound = Application.InputBox("Please enter the number of the first line item:", "First Line Item Number", , , , , , 1)
        upperbound = Application.InputBox("Please enter the number of the last line item:", "Last Line Item Number", , , , , , 1)
        If lowerbound < upperbound And lowerbound > 0 Then
            Repeat = False
        End If
    Wend
    MsgBox "Done"
End Sub

如果上界可以等于下界则使用:

If lowerbound <= upperbound And lowerbound > 0 Then