2014-01-28 183 views
0

今天早些時候我在這裏得到了這段代碼,只是試圖去適應它。我在線Set Rng =上收到運行時錯誤13,我不太確定爲什麼(?)任何幫助表示讚賞。運行時錯誤13類型錯誤匹配VBA Excel 2010

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 

回答

2

嘗試在該行Set Rng = .Range("Table1").Find(...刪除After:=.Range("Table1"),

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

感謝simoco。作品一種享受。 – JimQ

相關問題