I would employ a user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)
I have provided two udfs. Neither is perfect but perhaps the second one may be closer to what you want?
The first looks for any "
word" after the final "-" in column A in column B
The second looks for the
whole exact text after the final "-" in column A in column B
VBA Code:
Function MatchWord(sCCBSI As String, sCountry As String) As String
Dim RX As Object
Set RX = CreateObject("VBScript.RegExp")
RX.Pattern = "\b(" & Replace(Trim(Split(sCCBSI, "-")(2)), " ", "|") & ")\b"
MatchWord = "No"
If RX.test(sCountry) Then MatchWord = "Yes"
End Function
Function MtchWrd(sCCBSI As String, sCountry As String) As String
Dim RX As Object
Set RX = CreateObject("VBScript.RegExp")
RX.Pattern = "\b" & Trim(Split(sCCBSI, "-")(2)) & "\b"
MtchWrd = "No"
If RX.test(sCountry) Then MtchWrd = "Yes"
End Function
ikhil0311 2020-04-02 1.xlsm |
---|
|
---|
| A | B | C | D |
---|
1 | Country 1 | Country 2 | MatchWord | MtchWrd |
---|
2 | CCBSI-INTERNATIONAL HQ - INDIA | INDIA | Yes | Yes |
---|
3 | CCBSI-INTERNATIONAL HQ - JAPAN | | No | No |
---|
4 | CCBSI-INTERNATIONAL HQ - KOREA | KOREA REPUBLIC OF | Yes | Yes |
---|
5 | CCBSI-INTERNATIONAL HQ - NEW ZEALAND | NEW ZEALAND | Yes | Yes |
---|
6 | CCBSI-INTERNATIONAL HQ - INDONESIA | AUSTRALIA | No | No |
---|
7 | CCBSI-INTERNATIONAL HQ - NEW ZEALAND | NEW CALEDONIA | Yes | No |
---|
8 | CCBSI-INTERNATIONAL HQ - SOUTH KOREA | NORTH KOREA | Yes | No |
---|
9 | CCBSI-INTERNATIONAL HQ - UNITED KINGDOM | UNITED STATES OF AMERICA | Yes | No |
---|
10 | CCBSI-INTERNATIONAL HQ - SOUTH SUDAN | SUDAN | Yes | No |
---|
11 | CCBSI-INTERNATIONAL HQ - SUDAN | SOUTH SUDAN | Yes | Yes |
---|
|
---|