2017-06-21 40 views
0

我寫了下面的代碼:VBA - 訪問文本值錯誤

Function Find_Index(Gender As String) 

    Dim Index As Long 

    Do While Gender = Worksheets("Source").Cells(Index, "A").Text 

     Index = Index + 1 

    Loop 

    Find_Index = Index 

End Function 

,我發現了以下錯誤:

「應用程序定義或對象定義的錯誤」

由於到代碼中的以下行:

Do While Gender = Worksheets("Source").Cells(Index, "A").Text 

任何想法爲什麼?

回答

3

您定義了Index,但在使用它之前從未將其設置爲值。

添加Index = 1Do While

+0

之前,我無法相信我錯過了。非常感謝你! – Jordan

+1

沒問題 - 我們都是人類! – Dave