As Peter mentioned there are no VBA constructs. However, you may be
able to leverage the application's capabilities. For example, if your
code is based on an Excel platform, the following works with a 1D
array:
Sub testMatch()
Dim Arr()
ReDim Arr(1 To 3)
Arr(1) = 10: Arr(2) = 20: Arr(3) = 30
MsgBox Application.WorksheetFunction.Match(20, Arr, 0)
End Sub
You can extend the concept to searching any one dimension of a 2D array
(!) with
Sub testMatch()
Dim Arr()
ReDim Arr(1 To 3)
Arr(1) = 10: Arr(2) = 20: Arr(3) = 30
MsgBox Application.WorksheetFunction.Match(20, Arr, 0)
ReDim Arr(1 To 2, 1 To 3)
Arr(1, 1) = 1: Arr(1, 2) = 2: Arr(1, 3) = 3
Arr(2, 1) = 10: Arr(2, 2) = 20: Arr(2, 3) = 30
With Application.WorksheetFunction
MsgBox .Match(20, .Index(Arr, 2), 0)
MsgBox .Match(3, .Index(Arr, 1), 0)
End With
End Sub
And, you can even 'slice' the matrix the other way around (!) with:
MsgBox .Match(2, .Index(Arr, 0, 2), 0)
Ah, the power of leveraging the application's object model.
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions