Reputation: 93
In VBA, i have a function to get data and save it in array:
Function GetAppro(Current_Sheet As String)
Dim myArray As Variant
myArray = Worksheets(Current_Sheet).Range("A3:C6")
GetAppro = myArray
End Function
In other function, i would like read a value in array:
Sub GenerateDB()
Dim Appro() As Variant
Appro = GetAppro("Sheet1")
MsgBox Appro(0, 0) 'Error come from here
End Sub
EXcel say me error 9 out of range.
Upvotes: 0
Views: 102
Reputation: 2167
Array index starts at 1 in this instance. Use:
Sub GenerateDB()
Dim Appro() As Variant
Appro = GetAppro("Sheet1")
MsgBox Appro(1, 1) 'Error come from here
End Sub
Upvotes: 3