簡體   English   中英

Excel VBA .Find()錯誤

[英]Excel VBA .Find() error

我有以下一段VBA代碼,但是運行它時,我得到了無限MsgBoxes,在ID地址上方4行向我顯示相同的地址。 我必須使用Ctrl + Break停止執行。

我一直在嘗試使代碼正常工作,在我看來,該錯誤來自Find()方法。 在我的代碼的其他版本中,我得到對象“ Range”的“方法'Find'失敗。有關如何解決此問題的任何想法?謝謝。

Function CheckFinancials(ID As Integer) As Double
    Dim MyArray(1 To 4) As Integer
    Dim Guide As Range
    Set Guide = Worksheets("Financials").Range(Cells(1, 1),Cells(Worksheets("Financials").UsedRange.Rows.Count, 1))
    Set Guide = Guide.Find(ID)

    MsgBox Guide.Address

您的發現缺少很多參數(嘗試記錄下來,您將看到),測試一下:

Function CheckFinancials(ID As Integer) As Double
    Dim MyArray(1 To 4) As Integer
    Dim Guide As Range
    Set Guide = Worksheets("Financials").Range(Cells(1, 1), Cells(Worksheets("Financials").UsedRange.Rows.Count, 1))
    Set Guide = Guide.Find(What:=ID, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

    MsgBox Guide.Address

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM