See attached as example. RUN button "Data" invokes macro.
Sheet "Table" contains demonyms vs Country. Sheet "Data" has text containing the demonyms and column B the resulting country.
Sub Get_Country()
Dim SrchRng() As Variant
Dim InVar() As Variant
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim r As Long
Dim i As Long
Dim lastrow As Long
Application.ScreenUpdating = False
Set ws1 = Worksheets("Table")
Set ws2 = Worksheets("Data")
With ws1
lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
SrchRng = .Range("A2:B" & lastrow)
End With
ws2.Activate
With ws2
lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
InVar = .Range("A1:A" & lastrow)
For r = 1 To UBound(InVar, 1)
' Find Table Match ......
For i = 1 To UBound(SrchRng, 1)
If InStr(1, UCase(InVar(r, 1)), UCase(SrchRng(i, 1))) > 0 Then
.Cells(r, 2) = SrchRng(i, 2)
Exit For
End If
Next i
Next r
End With
Application.ScreenUpdating = True
End Sub
Bookmarks