如何在VBA中find大于零的第一个值?

我知道这很容易在VBA之外完成,但是我想要熟练使用VBA作为初学者。

我有一个长列(约25000行)。 我需要find该列中第一个单元格值大于零的实例。 然后我需要将该单元格的地址返回给variables。 到目前为止,我一直在使用循环没有成功,有什么build议吗?

你可以很容易地做到以下几点:

For each c in Range("A1:A25000").Cells If c.Value > 0 Then firstValue = c.Value firstAddress = c.Address Exit For End If Next MsgBox "The first value greater than zero is in cell " & firstAddress & _ "; - it has value " & firstValue 

这应该工作

 Function not_zero() AS String Dim lcell as Range For Each lcell in Range("$YOUR COLUMN LETTER$1","$YOUR COLUMN LETTER$LAST ROW") If CLng(lcell.value) > 0 then not_zero = lcell.Address Exit For End If Next lcell End Function