0

This is not the usual case where the array is defined within Excel. It is defined within VBA, and I need to find the proper value given a value found in a cell in Excel. In cell A1 I have the value DE000C5RQDA9. In B1 I want to return RXM1.

The actual array is more of a (0 to 9, 0 to XX) so do not think a dictionary is feasible. XX changes dynamically.

Example

 Sub Test()

 Dim arr(0 To 1, 0 To 1)
 arr(0,0) = "RXM1"
 arr(0,1) = "UBM1"
 arr(1,0) = "DE000C5RQDA9"
 arr(1,1) = "DE000C5RQDD3"
 
With Application
   ActiveSheet.Cells(1, 2) = .Index(arr(0), .Match(ActiveSheet.Cells(1,1), arr(1), 0))
End with

 End sub
2
  • Firstly, arr(0) and arr(1) have no meaning for a 2D array. Then, you tried a code for an array with two rows and two columns. What the code should return for an array having 9 rows and 10 columns, supposing that the vale in Cells(1, 2) matches the one in column 4, row 3? Commented Apr 13, 2021 at 11:05
  • 1
    The idea is you can match a value in a 1D array. The good news is you can slice rows or columns in a 2D array, making them 1D arrays and (if want only using Index - Match) try matching (only) between the two such columns. This means that you must know what columns to match for the case of more than two columns in the array... Commented Apr 13, 2021 at 11:44

1 Answer 1

3

You can use Application.Index to get the columns you want to use in the INDEX/MATCH.

The same idea could be used for rows.

Sub Test()
Dim arr(0 To 1, 0 To 1)
Dim col1 As Variant
Dim col2 As Variant

    arr(0, 0) = "RXM1"
    arr(0, 1) = "UBM1"
    arr(1, 0) = "DE000C5RQDA9"
    arr(1, 1) = "DE000C5RQDD3"

    col1 = Application.Index(arr, 1)
    col2 = Application.Index(arr, 2)
    With Application
        ActiveSheet.Cells(1, 2) = .Index(col1, .Match(ActiveSheet.Cells(1, 1), col2))
    End With

End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

... or ... = .Index(Arr, .Match(Tabelle2.Cells(1, 1), col2), 1) avoiding at least the 1st column slice :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.