Sub sayHello()
Dim i As Integer
Dim j As Integer
Dim isContainsKey As Boolean
Dim index As Integer
Dim stringKeydai As String
Dim stringKeyNgan As String
Dim stringBefore, stringAfter As String
For i = 2 To 221 'Vi tri bat dau va ket thuc list key dai
stringKeydai = Cells(i, 1).Value
For j = 2 To 9917 'Vi tri bat dau va ket thuc list key ngan
stringKeyNgan = Cells(j, 2).Value
index = InStr(stringKeydai, stringKeyNgan)
If index = 0 Then 'Khong chua key
Else
'Kiem tra vi tri truoc, va sau phai la khoang trang hay khong
If index > 1 Then
stringBefore = Mid(stringKeydai, index - 1, 1)
End If
If index + Len(stringKeyNgan) <= Len(stringKeydai) Then
stringAfter = Mid(stringKeydai, index + Len(stringKeyNgan), 1)
End If
If stringBefore = " " And stringAfter = " " Then
isContainsKey = True
stringKeydai = Application.Trim(Replace(stringKeydai, stringKeyNgan, ""))
End If
End If
Next
If isContainsKey = False Then
Cells(i, 3) = stringKeydai
Else
Cells(i, 4) = stringKeydai
End If
isContainsKey = False
Next
End Sub