I have four loops to populate and compare two two-dimensional arrays then add the results to the first array before writing back to the active worksheet. Wondering if anyone has a cleaner alternate or more elegant method? It works as is but haven't tested it on large arrays yet!Function lastRow(x As Range, y As Worksheet)lastRow = y.Cells(Rows.Count, x.Column).End(xlUp).RowEnd FunctionSub arrayMatch()Dim arr1() As VariantDim arr2() As VariantDim rowX As Byte, colX As Byte, aX As ByteDim arr1x As Long, arr2y As Longarr1x = lastRow(Range(A1), ActiveSheet) 'returns the last row in the column for cell A1arr2y = lastRow(Range(A1), Sheets(2)) 'returns the last row in the column for cell A1 on sheet2ReDim arr1(1 To arr1x, 1 To 4) As Variant 'dynamically sizes arr1 arrayReDim arr2(1 To arr2y, 1 To 2) As Variant 'dynamically sizes arr2 arrayFor rowX = 1 To arr1x 'arr1x is the last row in the active sheet and the end of array arr1    For colX = 1 To 3 'only fills array up to 3rd dimension as 4th is reserved for the match results        arr1(rowX, colX) = Cells(rowX, colX).Value 'set the Cells range to whatever your array is    Next colXNext rowXFor rowX = 1 To arr2y 'arr2y is the last row in sheet 2 and the end of array arr2    For colX = 1 To 2        arr2(rowX, colX) = Sheets(2).Cells(rowX, colX).Value    Next colXNext rowXFor aX = 1 To arr1x    For rowX = 1 To arr2y        If arr1(aX, 3) = arr2(rowX, 1) Then            arr1(aX, 4) = arr2(rowX, 2)            rowX = arr2y 'helps to exit array earlier when a match is found        End If    Next rowXNext aXFor rowX = 1 To arr1x    Cells(rowX, 4).Value = arr1(rowX, 4)Next rowXEnd Sub
Compare and match results in two two-dimensional arrays in Excel VBA
vba
This is a cleaner approach to filling the arrays. Dim arr1, arr2arr1 = Worksheets(1).Range(C1, Worksheets(1).Range(A & Rows.Count).End(xlUp))ReDim Preserve arr1(UBound(arr1, 1), 1 To 4)arr2 = Worksheets(1).Range(B1, Worksheets(2).Range(A & Rows.Count).End(xlUp))