gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:19:37 28 4
gpt4 key购买 nike

我让用户输入下限和上限,然后我用它来过滤行。例如,如果他们为下限输入 4,为上限输入 8,然后我使用这些数字来过滤第一个单元格中包含 4、5、6、7 或 8 的行。
我的代码(我将在下面显示)确保用户只能输入一个数字(通过将 type 指定为 1),但我想确保他们输入的第二个数字总是大于第一个。不确定我目前使用两个不同的输入框是否可以做到这一点,但我不确定还能如何做到这一点,因为这只是我在 VBA 中编码的第四天。我还想确保他们为下限和上限输入的数字都大于 0。
这是我的 InputBoxes 代码:

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

关于excel - 如何确保在 InputBox 中输入的数字小于在 VBA 中 InputBox 中输入的另一个数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65312641/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com