I'm working on this project and I need to create a function in VBA in order to store a formula and return the result in excel using the index function. My code is as below and i created just a simple dummy function for testing purposes. In excel I believe the function should be =INDEX(NewArray,,1)? Any help on this would be greatly appreciated Thanks
Public Function NewArray(a As Integer, b As Integer) As Long()
Dim arr() As Long
ReDim arr(1 To 10, 1 To 5) As Long
Dim row As Integer
Dim col As Integer
For row = 1 To 5
arr(row, 1) = (row + 1)
Next row
NewArray = arr(a, b)
End Function
Long()? Should be aLong, if you're returning a single element from the array and not the array itself.NewArray = arrand=INDEX(NewArray(1,1),5,1)for example. It's not clear why your function has unused parameters, but you must supply them...