I am trying to get the index of the item in an array VBA, but I have issue getting it.
Const NoOfVol As Integer = 5
Dim vol(NoOfVol) As Integer
For Index = 1 To NoOfVol
vol(Index) = Cells(15 + Index, 8).Value
Next
The array looks like this: (-2500,-1250,0,1250,2500). I am calling the function this way.
Function Find(ByVal Value As Variant, arr As Variant) As Integer
Find = Application.Match(Value, arr, False)
End Function
posOfVol = Find(-1250, vol)
But the posOfVol = 3, when it should be 2. Not sure where my error is. Need some guidance on this.
Option Base 1statement, your array dimensions are 0 to 5, not 1 to 5.(0,-2500,-1250,0,1250,2500)since you didn't populate the first element and you are looking for an exact match.Option Base 1, you can be explicitly in the dimension of your array:Dim vol(1 to NoOfVol) As IntegerUbondandLbound.