Excel VBA.Find()行为异常无法找到字符串

Excel VBA.Find()行为异常无法找到字符串,vba,excel,Vba,Excel,我在一张纸上有一系列的值 E11:“概念性” E12:“罢工” E13:“优惠券” 等等 在我的代码中,使用图纸名称 Function AddInput(name As String, strInput As String, Optional suffix = "") As String Dim inputVal As Variant On Error GoTo ERROR_FUNCTION With Worksheets(name) If .Cells.Find(wha

我在一张纸上有一系列的值

E11:“概念性”

E12:“罢工”

E13:“优惠券”

等等

在我的代码中,使用图纸名称

Function AddInput(name As String, strInput As String, Optional suffix = "") As String
Dim inputVal As Variant
On Error GoTo ERROR_FUNCTION
    With Worksheets(name)
        If .Cells.Find(what:=strInput, LookAt:=xlWhole,searchorder:=xlByRows).Offset(0, 1).Value <> "" Then
            inputVal = Trim(Cells.Find(what:=strInput, LookAt:=xlWhole,     searchorder:=xlByRows).Offset(0, 1).Value)
            If TypeName(inputVal) = "Date" Then inputVal = Format(inputVal, "YYYYMMDD")
        AddInput = Replace(strInput, " ", "") & "=" & inputVal & "&"
            If suffix <> "" Then AddInput = AddInput & suffix
        Else
            AddInput = ""
        End If
    End With

Exit Function
ERROR_FUNCTION:
    Debug.Print strInput & ": input not found"
    MsgBox strInput & ": input not found"
End Function
函数AddInput(名称作为字符串,strInput作为字符串,可选后缀=”)作为字符串
作为变量的Dim inputVal
关于Error GoTo Error_函数
带工作表(名称)
如果.Cells.Find(what:=strInput,LookAt:=xlWhole,searchorder:=xlByRows).Offset(0,1).Value“”则
inputVal=Trim(Cells.Find(what:=strInput,LookAt:=xlother,searchorder:=xlByRows).偏移量(0,1).Value)
如果TypeName(inputVal)=“日期”,则inputVal=格式(inputVal,“yyyyymmdd”)
AddInput=Replace(strInput,“,”)&“=”&inputVal&“&”
如果后缀为“”,则AddInput=AddInput&后缀
其他的
AddInput=“”
如果结束
以
退出功能
错误\u函数:
调试。打印strInput&“:找不到输入”
MsgBox strInput&“:未找到输入”
端函数
我可以在单元格E12中找到什么,但在单元格E11中找不到。
我已经做了以下工作:

1) 我直接将单元格值复制到搜索函数中(没有机会胖指它)

2) 我从E11向下复制了值1(如果出于某种原因,它找不到该范围等,它只返回E12)

我仍然找不到一个单元格,它对我输入的每一个值都有效

有人遇到过这种情况吗?您是如何解决的


谢谢

确保正确启动每个搜索:

Sub dural()
    Dim r As Range
    strSheetname = ActiveSheet.Name
    MyInputString = Application.InputBox(Prompt:="Enter value", Type:=2)
    With Sheets(strSheetname)
        Set r = .Cells.Find(what:=MyInputString, After:=Range("A1"))
    End With
    MsgBox r.Address(0, 0)
End Sub

请注意,“查找”只在可见单元格中查找内容。它是一个可见单元格。@Kelvin您发布的代码片段实际上没有任何作用。你的第二行不完整。再加上您的代码不起作用,我想说我们没有足够的信息来说明原因,但这可能是由于您尚未发布的代码中存在问题。请使用更多代码进行编辑