(Solved) – Find Match between two uneven Variant arrays VBA

(solved)-–-find-match-between-two-uneven-variant-arrays-vba

Thanks for taking the time to help me solve this! I’m a noob in need to check if each string in arr1 has a match in arr2, if it has a match then it should write “Match” to the column next to arr1, if not then “Not Match”.

Here’s how my sheet looks:

How my Sheet looks

Sub Variant_Array_Question()
'Here is my frankenstein monster of a code
    Dim DocNm As Variant, NroNm As Variant
    Dim i As Long, j As Long
    Dim NroLastRow As Long, DocLastRow As Long

    'Arr1
    DocLastRow = ShStart.Range("Q" & Rows.Count).End(xlUp).Row
    DocNm = ShStart.Range("Q6:Q" & DocLastRow).Value

    'Arr2
    NroLastRow = ShStart.Range("T" & Rows.Count).End(xlUp).Row
    NroNm = ShStart.Range("T6:T" & NroLastRow).Value

    For i = 1 To UBound(DocNm)
        For j = 1 To UBound(NroNm)
            If DocNm(i, 1) = NroNm(j, 1) Then
                'Match was found ==== Run into Problem here
                DocNm(i, 1).Offset(0, 1).Value = "Match"
                Exit For
            End If
        Next j
        If i > UBound(NroNm) Then
            'No match was found ==== Run into Problem here
            DocNm(i, 1).Offset(0, 1).Value = "Not Match"
        End If
    Next i
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *