运行时错误13键入错误匹配VBA Excel 2010

时间:2014-01-28 14:44:15

标签: excel-vba error-handling vba excel

我今天早些时候在这里找到了这个代码,并试图适应它。我在行Set Rng =上收到运行时错误13,我不太清楚为什么(?)有任何帮助表示赞赏。

Sub PlayMacro()

  Dim Prompt As String
  Dim RetValue As String
  Dim Rng As Range
  Dim RowCrnt As Long

  Prompt = ""

      With Sheets("Claims")

    Do While True

  RetValue = InputBox(Prompt & "Give me a value to look for")
  'RetValue will be empty if you click cancel

  If RetValue = "" Then
    Exit Do
  End If

  ' I do not wish to active the cell containing the required value.
  ' I want to know where it is.
  Set Rng = .Range("Table1").Find(What:=RetValue, After:=.Range("Table1"), _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

  If Rng Is Nothing Then
    ' The entered value could not be found
    Prompt = "I could not find """ & RetValue & """"
  Else
    ' The entered value was found
    RowCrnt = Rng.Row
    Prompt = "I found """ & RetValue & """ on row " & RowCrnt
  End If
  Prompt = Prompt & vbLf
Loop

End With

End Sub

1 个答案:

答案 0 :(得分:2)

尝试删除行After:=.Range("Table1"),中的Set Rng = .Range("Table1").Find(...

Set Rng = .Range("Table1").Find(What:=RetValue,  _ 
        LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)