在VBA中,我有一个获取数据并将其保存在数组中的函数:
Function GetAppro(Current_Sheet As String)
Dim myArray As Variant
myArray = Worksheets(Current_Sheet).Range("A3:C6")
GetAppro = myArray
End Function
在其他函数中,我想读取数组中的值:
Sub GenerateDB()
Dim Appro() As Variant
Appro = GetAppro("Sheet1")
MsgBox Appro(0, 0) 'Error come from here
End Sub
EXcel说错误9超出范围。
答案 0 :(得分:3)
在此实例中,数组索引从1开始。使用:
Sub GenerateDB()
Dim Appro() As Variant
Appro = GetAppro("Sheet1")
MsgBox Appro(1, 1) 'Error come from here
End Sub