Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 错误9由于。查找_Vba_Excel - Fatal编程技术网

Vba 错误9由于。查找

Vba 错误9由于。查找,vba,excel,Vba,Excel,嗨,我想找到一个包含变量“AI”的单元格,然后选择该行。搜索结果可能是空的,如果是这种情况,它应该写一个文本 这是到目前为止我的代码 Private Sub Worksheet_Change(ByVal Target As Range) Dim KeyCells As Range Dim mf As Object Dim RZ As String Dim AI As String ' The variable KeyCells contains the cells that will ' c

嗨,我想找到一个包含变量“AI”的单元格,然后选择该行。搜索结果可能是空的,如果是这种情况,它应该写一个文本

这是到目前为止我的代码

Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Dim mf As Object
Dim RZ As String
Dim AI As String


' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("B3")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
       Is Nothing Then

    ' Place your code here.

AI = Range("B3").Value
Sheets("DATA").Select
Sheets("DATA").Columns("C:C").Select

Set mf = Sheets("DATA").Columns("C:C").Find(What:=AI, LookAt:=Whole, SearchOrder:=xlByRows, SearchDirection:= _
    xlNext, SearchFormat:=False)
    If Not mf Is Nothing Then

    RFound = mf.Row
    Sheets("DATA").Cells(RFound, 1).Select
    RZ = Sheets("DATA").Cells(RFound, 2).Value2
    Sheets("Búsqueda").Select
    Cells(3, 6).Value = RZ
    Else
    Cells(3, 6).Value = "RAZON SOCIAL"

    End If
End If
End Sub
问题是

Set mf = Sheets("DATA").Columns("C:C").Find(What:=AI, LookAt:=Whole,      SearchOrder:=xlByRows, SearchDirection:= _
    xlNext, SearchFormat:=False)
返回“错误9超出范围”

。。。应该是:

LookAt:=xlWhole 
应该归功于@simoco,因为他提供了答案。

我不确定是否有适当的礼节(即使在检查Meta之后)

  • 理想情况下,simoco应将其评论转换为官方答案(并应予以接受)。他当然应该得到表扬
  • 同时,问题应该会得到答案,所以我正在填写。如果我的回答被接受,这将有助于社区澄清决议

我可以投票结束,但这似乎不仅仅是一个打字错误。这似乎是一个质量很好的问题。

LookAt:=Whole
-->
LookAt:=xlWhole
确实有效!我改变了它,因为xlWhole不仅找到了整个单词,但现在它似乎起作用了。非常感谢。
LookAt:=xlWhole