vba 大于和小于范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8083850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Greater Than and Less Than Range
提问by Kush Parikh
I am trying to go through random numbers between 0 and 1 and group them into an array. Each array holds the value of numbers from 0 to 0.1, 0.1 to 0.2, etc. How do I write the If
statement to get my code to include the 0.1? As of now, it is only reading the greater than 0 part.
我试图通过 0 和 1 之间的随机数并将它们分组到一个数组中。每个数组都包含从 0 到 0.1、0.1 到 0.2 等的数字值。如何编写If
语句以使我的代码包含 0.1?截至目前,它只读取大于 0 的部分。
This is what I have:
这就是我所拥有的:
If Range("A1").Offset(i - 1, 0).Value > 0 < 0.1 Then
count1 = count1 + 1
回答by BlackBear
You have to use a temporary variable because you have check it two times:
您必须使用临时变量,因为您已经检查了两次:
dim temp as single
temp = Range("a1").Offset(i - 1, 0).Value
if temp >= 0 and temp < 0.1 then
' ...
else if temp >= 0.1 and temp < 0.2 then
' ...
'...
Or you can do it in a more clever way:
或者你可以用更聪明的方式来做到这一点:
dim index as integer
index = temp / 0.1
' et-voilà, you know where to insert it
回答by Tomalak
Dim value As Double
value = Range("a1").Offset(i - 1, 0).Value
If value > 0 And value < 0.1 Then
' ...
End If