Vba 大于和小于范围

Vba 大于和小于范围,vba,excel,Vba,Excel,我试图通过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 If范围(“A1”)。偏移量(i-1,0)。值>00且值

我试图通过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
If范围(“A1”)。偏移量(i-1,0)。值>0<0.1,则
count1=count1+1
将变暗值设置为双精度
值=范围(“a1”)。偏移量(i-1,0)。值
如果值>0且值<0.1,则
' ...
如果结束
将变暗值设置为双精度
值=范围(“a1”)。偏移量(i-1,0)。值
如果值>0且值<0.1,则
' ...
如果结束

您必须使用临时变量,因为您已对其进行了两次检查:

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