2011-11-10 121 views
0

我想通过0和1之间的随机数并将它们分组到一个数组中。每个数组都保存从0到0.1,0.1到0.2等数字的值。我如何编写If语句来让我的代码包含0.1?截至目前,它只读取大于0的部分。大于和小于范围

这是我有:

If Range("A1").Offset(i - 1, 0).Value > 0 < 0.1 Then 
count1 = count1 + 1 

回答

1
Dim value As Double 

value = Range("a1").Offset(i - 1, 0).Value 

If value > 0 And value < 0.1 Then 
    ' ... 
End If 
2

你,因为你必须检查两次使用一个临时变量:

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 
    ' ... 
'... 

或者你可以在一个更做巧妙的方式:

dim index as integer 
index = temp/0.1 

' et-voilà, you know where to insert it