1
我想知道如何訪問由函數返回的數組值。 據我所知,返回的值應該有相同的函數名稱。訪問由VBA宏函數返回的數組
Function PathFinder(sheet1 As String, word1 As String) As Integer()
Dim rng As Range
Dim rngFound As Range
Dim temp(1, 2)
Set rng = Sheets(sheet1).Range("A:D")
Set rngFound = rng.Find(word1, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "not found"
Else:
temp(1, 1) = rngFound.Row
temp(1, 2) = rngFound.Column
PathFinder = temp
End If
End Function
這已經完成,我沒有找到如何訪問到值「探路者(1,1)」和「探路者(1,2)」
預先感謝您爲您的幫助
1)它不工作 - 它給你_compile error_ on line'PathFinder = temp',因爲'Dim temp(2)'是變體數組,'PathFinder'返回'Integer'數組2),如果沒有發現,'Debug.Print arr(1)'給你_runtime error_ –
I已經改變了一些代碼。它現在有效 – Kozyr