excel vba:find一个具有特定值的单元格的行,并将该行号放入另一个单元格中

我试图find一个具有特定值的单元格的行(与range("C1").value ),并将该行号放入另一个单元格中。 我坚持了两个小时。

我的代码如下:(我之前激活过sheet1)

 Set found = sheet1.Columns("B").Find(what:= sheet1.range("C1").Value, LookIn:=xlValues, lookat:=xlWhole) sheet1.range("A2").value= found.Address 

此代码得到错误消息Object variable not set

这个错误的来源是什么?

B'cosfind的variables是空的,因为Find()没有find任何匹配的值,也没有在find的variables中设置任何东西。

 Dim found As Range Set found = Sheet1.Columns("B").Find(what:=Sheet1.Range("C1").Value, LookIn:=xlValues, lookat:=xlWhole) If Not found Is Nothing Then Sheet1.Range("A2").Value = found.Address End If