答案 0 :(得分:1)
假设您有从J1
到J5
的国家/地区列表,如下面的屏幕截图所示。
在模块中复制并粘贴以下功能。见截图。
Option Explicit
Public Function getCountry(ByVal srtText As String) As String
Dim CountryArray As Variant
Dim i As Long
Application.Volatile
CountryArray = Application.Transpose(Range("J1:J5").Value2)
For i = LBound(CountryArray) To UBound(CountryArray)
If (InStr(1, srtText, CountryArray(i), 1)) > 0 Then
getCountry = CountryArray(i)
Exit Function
End If
Next i
End Function
答案 1 :(得分:1)
首先列出一个国家/地区列表 - 最好是 - 另一张表格。下面的屏幕截图是 Sheet2 :
上的示例列表假设您的数据位于下方,请将以下公式写入 Sheet1 的B1
,然后按 Ctrl + Shift + 输入以激活数组公式。
=INDEX(Sheet2!$A$1:$A$5,SUMPRODUCT(ISNUMBER(FIND(Sheet2!$A$1:$A$5,A1))*ROW(Sheet2!$1:$5)))
Sheet2!$A$1:$A$5
& ROW(Sheet2!$1:$5)
相应的部分。答案 2 :(得分:0)
'As far as I know this task can be achieve if we have list of all country.
'here CountyText.text file contain list of all country.
'for demo this list collect from internet you can add your own list in this file.
'This function can be use where compitational time doesn't matter.
'Before use this function copy paste this code in new module.
Function FindCountry(cellstring As String) As String
Dim DataLine As String
Dim File As String
File = "D:\CountyText.txt" 'Path of county text file
'(for demo this list collect from internet) you can add your own list in this file
FindCountry = "" 'initial value of function
On Error Resume Next 'this is for error handling
Close #1
Open File For Input As #1
On Error GoTo 0
While Not EOF(1) 'while end of file
Line Input #1, DataLine ' read in data 1 line at a time
If InStr(cellstring, DataLine) Then
FindCountry = DataLine
End If
Wend
Close #1
End Function
编写countryText.txt文件格式见截图
添加" USA"在countryText.txt文件中,它可以识别
答案 3 :(得分:0)
您可以在单元格B2
中使用公式,如下所示:
=LOOKUP(2^15,SEARCH(CountryList,A2,1),CountryList)
其中
CountryList
是指包含您要查找的国家/地区名称的范围!