0

Truly stumped here. Simple example of what I am trying to do. I build a 10 row, 4 column matrix, that goes A1 to C1 on a row and down to "a10" row.

I am trying to perform a lookup. The lookup works perfectly well if I look up using the first column value. So if I want to get C2, I can do that using A2.

But, how do I lookup things in the array using column b? Here is the code, already spent 3 hours with Chat GPT, but it can't figure this one out. Can anyone help?

Sub ConceptCode()
    Dim myArray(1 To 10, 1 To 4) As Variant
    Dim i As Variant
    Dim inputDimensionB As Variant
    Dim outputDimensionC As Variant
    
    For i = 1 To 10
        myArray(i, 1) = "a" & i
        myArray(i, 2) = "b" & i
        myArray(i, 3) = "c" & i
        myArray(i, 4) = "d" & i
    Next i
    
    For i = 1 To UBound(myArray, 1)
    For j = 1 To UBound(myArray, 2)
        Cells(i, j).Value = myArray(i, j)
    Next j
Next i
    
    
 inputDimensionB = myArray(2, 1)  < ----- does not work, how do i search using second column values?
inputDimensionB = myArray(1, 2)    < ---- works because its the first column in array
    
    outputDimensionC = Application.VLookup(inputDimensionB, myArray(), 4, False)
    
    MsgBox "The value of Dimension C is: " & outputDimensionC

End Sub

I was hoping to get the value of any column, using a lookup on a VBA multidimensional array using any other column.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125

0 Answers0