[英]excel vba: find the row of a cell with a certain value and put that row number in another cell
我正在嘗試找到具有特定值的單元格行(與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'cos找到的變量是空的,因為Find()沒有找到任何匹配的值,也沒有在找到的變量中設置任何東西。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.