大于和小于范围

我试图通过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 

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

 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 
 Dim value As Double value = Range("a1").Offset(i - 1, 0).Value If value > 0 And value < 0.1 Then ' ... End If