【发布时间】:2017-02-07 05:44:19
【问题描述】:
基本上,我试图循环遍历数组中的所有值,并计算大于用户指定值的值的数量,方法是使用 Inputbox 并尝试使用 IF 语句来确保介于 1 和输入 100。完成后,我只想简单地在消息框中显示结果。
这是我目前所拥有的:
Dim arr As Variant
arr = Range("A1:J10")
Range("A1").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
Dim val As String
val = InputBox("Enter an integer value")
If val < 1 Or val > 100 Then
' tells the user to try again
MsgBox "You did not enter a value from 1 to 100 , try again"
val = Inputbox("Enter an integer value")
Else
End If
基本上是在用 if 语句来验证用户输入的内容并循环遍历数组。
【问题讨论】:
-
我假设您希望在 if 语句中使用
or,因为val不能同时小于 1 和大于 100。 -
啊对的好点!