Public Function Thay(Vung, Cll) As String
Dim I, J, VuDo, Tam, K, Kt, KtThay, Wf
Set Wf = Application.WorksheetFunction
VuDo = Replace(Cll, " ", ""): Cll = Replace(Cll, " ", ""): Cll = Replace(Cll, "-", " "): Cll = Replace(Cll, "+", " ")
For I = 1 To Len(Cll)
If I = InStrRev(Cll, " ") + 1 Then
KtThay = KtThay & Right(Cll, Len(Cll) - InStrRev(Cll, " "))
KtThay = IIf(Val(KtThay) = 0, KtThay, Val(KtThay))
If Wf.CountIf(Vung, KtThay) Then
Tam = Tam & Vung(Wf.Match(KtThay, Vung, 0)).Offset(, 1)
Exit For
Else
Tam = Tam & KtThay
Exit For
End If
Else
K = K + 1
Kt = Mid(Cll, I, 1)
If Kt = " " Then
KtThay = KtThay & Mid(Cll, I - K + 1, K - 1)
KtThay = IIf(Val(KtThay) = 0, KtThay, Val(KtThay))
If Wf.CountIf(Vung, KtThay) Then
Tam = Tam & Vung(Wf.Match(KtThay, Vung, 0)).Offset(, 1) & Mid(VuDo, I, 1)
K = 0: KtThay = ""
Else
Tam = Tam & KtThay & Mid(VuDo, I, 1)
K = 0: KtThay = ""
End If
End If
End If
Next I
Thay = Tam
End Function