我對VBA很陌生,只有基本的知識水平。VBA運行時錯誤13使用Msgbox
我一直在嘗試創建一個宏,以便在同一工作簿中的多張其他工作表上交叉引用一張工作表上的數據。如果找到記錄,我希望msgbox出現以提醒用戶數據的位置。
後幾個小時搜索互聯網和碼位拼湊這是我
Sub search()
Dim ws As Worksheet, found As Range
Dim TextToFind(1 To 20) As String
Dim iText As Long
TextToFind(1) = "Jade Smith"
TextToFind(2) = "Bob Collins"
TextToFind(3) = "Jemima Smythe"
For Each ws In ThisWorkbook.Worksheets
With ws
If .Name <> "Blacklisted Candidates" Then 'Do not search blacklist candidates!
iText = 1
Do While iText <= UBound(TextToFind)
If TextToFind(iText) <> "" Then 'Do not search blank strings!
Set found = .UsedRange.Find(what:=TextToFind(iText), LookIn:=xlformulas, LookAt:=xlPart, MatchCase:=False)
If Not found Is Nothing Then
MsgBox "Proxy Candidate Found at " & found.Address
Else
MsgBox "No Proxy Candidates Found ", vbOKOnly, "Success!"
End If
iText = iText + 1
End If
Loop
End If
End With
Next ws
End Sub
此代碼但不從其他表查找值。
當測試這個時,我只是得到msgbox時沒有數據被發現,即使有測試數據那裏。
我有一個約9張工作簿(不斷增長),我想搜索每個工作簿的前9列的指定數據,你可以看到我已經手動輸入到宏但運行宏即使有數據可以找到,我也不會返回任何結果。
爲什麼你最後有「*」? –
修改'* MsgBox(「代理候選人發現在和rngX.Address)''MsgBox」代理候選人在「&rngX.Address」找到 –
您是否遺漏了一些代碼? @litelite有正確的答案。錯誤13,但你的'Do'循環沒有任何辦法*退出*。另外'如果Rng被發現然後'應該是'如果不是沒有什麼然後'。 – Comintern