对于所有的值,但1,真正的(VBA)

我的循环遍历一个单元格范围,并比较值:

For k = 7 To wsPlany.UsedRange.Rows.Count If wsPlany.Cells(k, 1) = datu Then 'code here End If Next k 

基本上细胞是有数字的细胞1, 2, 3 ...datu也是一个数字。 这一切工作,但价值1,我不明白为什么。

甚至debug.printing类似于:wsPlany.Cells(k,1),datu并将它们比较到下一行确认,如果值是2或更高,它将返回该行的真,如果它是1,它返回false为如果它与其他数字比较(但我看到他们是相同的,他们并排在debug.print)。

一个简单的增加了1行,我把值转换为Integers不pipe他们在解决问题之前的数据types。

 For k = 7 To wsPlany.UsedRange.Rows.Count 'turns the values to integers first wsPlany.Cells(k, 1).Value = CInt(wsPlany.Cells(k,1)) If wsPlany.Cells(k, 1) = datu Then 'code here End If Next k