我收到错误:
Run-time error '91': Object variable or With block variable not set
当我尝试执行此代码时:
MsgBox Worksheets("Sheet2").Range("2:2").Find(Worksheets("Sheet1").Range("E5").Value, , , xlWhole)
为什么?这一行有什么问题?
编辑
如果我正在管理文本或数字,代码有效。但我有这个问题,我在Worksheets("Sheet1").Range("E5")
和Worksheets("Sheet2").Range("2:2")
上约会.
> 将result
分配给范围,然后使用.Find()
设置范围。 如果未找到任何内容,则Range()
Nothing
:
Sub TestMe()
Dim result As Range
With Worksheets(1)
Set result = .Range("2:2").Find("Something", LookAt:=xlWhole)
End With
If Not result Is Nothing Then
Debug.Print result.Address
Else
Debug.Print "Something is not on the second row!"
End If
End Sub
LookAt:=xlWhole
参数是必须的,如果一个人正在使用日期:
范围.在VBA Excel中查找1月和11月(2月和12月(之间没有区别
Excel.Range.Find 文档